开发者

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

开发者 https://www.devze.com 2023-01-24 08:41 出处:网络
I would like to replace that : $p = new sfWidgetFormI18nChoiceCountry(array(\'culture\' => \'en\'));

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

精彩评论

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