SonataNewsBundle CommentAdmin中的默认值是:
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('name')
->add('email')
->add('message')
;
}
在受保护的函数中,configureFormFields(FormMapper $formMapper)是:
protected function configureFormFields(FormMapper $formMapper)
{
if (!$this->isChild()) {
$formMapper->add('post', 'sonata_type_model_list');
// $formMapper->add('post', 'sonata_type_admin', array(), array('edit' => 'inline'));
}
$commentClass = $this->commentManager->getClass();
$formMapper
->add('name')
->add('email')
->add('url', null, array('required' => false))
->add('message')
->add('status', 'choice', array('choices' => $commentClass::getStatusList(), 'expanded' => true, 'multiple' => false))
;
}
我尝试添加到过滤器:
->add('status', null, array('label' => 'Status'), null, array('expanded' => true, 'multiple' => true))
但是这个抛出异常:
The options "expanded", "multiple" do not exist.
我也试过: ->add('status', 'doctrine_orm_callback', array(
'callback' => function($queryBuilder, $alias, $field, $value) {
if (!$value) {
return;
}
$queryBuilder->andWhere($alias . '.status = :status');
$queryBuilder->setParameter('status', $value);
return true;
},
'field_type' => 'choice'
))
现在显示错误,但选择为空。如何为此列表添加状态?我从文档中获取示例
也许更好的方法?
调用 add() 方法给出的参数顺序错误。请尝试以下操作:
$filters->add('status', null, array(), 'choice', array('choices' => $commentClass::getStatusList(), 'expanded' => true, 'multiple' => false))
表单选项在第 5 个参数上设置。