开发者

Symfony : what's the accessor of getCulture() in a form class?

I would like to replace that :

$p = new sfWidgetFormI18nChoiceCountry(array('culture' => 'en'));

by

$p = new sfWidgetFormI18nChoiceCountry(array('culture' => getCulture()));

but i'm missing one accessor to use getCulture and i can't reme开发者_运维技巧mber what.

What is the acessor to use getCulture on the form class ? What's your technique to remember the acessors ?

Thanks


You can use:

$culture = sfContext::getInstance()->getUser()->getCulture();

But the preferred Symfony way is to "inject" the culture into the form class from your action:

$this->form = new SomethingForm(array(), array('culture' => $culture)); // Inject it this way in your action

$culture = $this->getOption('culture'); // Get it like this in your form class
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜