【发布时间】:2013-11-22 10:29:42
【问题描述】:
似乎最简单的事情在 Symfony 2 中都很难做到;
像这样:
我有一个返回文化的服务:
public function getCultures()
{
$langs = LanguageQuery::create()->orderByPosition()->find();
$cultures = array();
foreach ($langs as $lang) {
$cultures[] = $lang->getCulture();
}
return $cultures;
}
我想在我的 FormType 中访问它:
现在..我无法在这里获取数据..(无法调用服务容器)..
而且我不想将 $CULTURES 作为 FormType 的参数,(这意味着我必须覆盖每个控制器中的每个函数)..(这不是很实用..)...有人有吗?一个好的解决方案?或者 Symfony 1.4 是否更适合这些简单的事情..
$builder
->add('commentI18ns', 'propel1_translation_collection', array(
'languages' => array($CULTURES),
'label' => '',
'options' => array(
'columns' => array(
'name' => array('label' => 'Name'),
'description' => array(
'label' => 'Description',
'type' => 'textarea',
)
),
'data_class' => 'MyDataClass'
)
))
->add('is_active')
;
【问题讨论】:
标签: symfony service containers