Symfony:getCulture()在表单类中的访问权限是什么?

时间:2010-11-11 15:46:41

标签: php forms symfony1 widget

我想替换它:

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

通过

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

但我缺少一个使用getCulture的访问器,我不记得是什么。

在表单类上使用getCulture的是什么?你有什么技巧可以记住acessors?

由于

1 个答案:

答案 0 :(得分:3)

您可以使用:

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

但首选的Symfony方法是将文化“注入”您的行动中的表单类:

$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