【发布时间】:2015-10-07 08:18:51
【问题描述】:
我有一个基于 Sonata 的 editAction 的自定义操作。只是形式不同。
公共函数 customAction(){
$id = $this->get('request')->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object) {
throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
}
if (false === $this->admin->isGranted('EDIT', $object)) {
throw new AccessDeniedException();
}
// On vérifie que l'annonce appartient bien à l'utilisateur connecté
if($this->getUser()->getId() !== $object->getUser()->getId()) {
throw new AccessDeniedException();
}
$em = $this->getDoctrine()->getManager();
$preparechoices = $em->getRepository('AcmeBundle:Entity')->findAll();
foreach($preparechoices as $c){
$choices[$c->getId()] = $c->getLibelle();
}
$form = $this->createFormBuilder(array('choix'=>1))
->add('choix','choice',array('choices'=>$choices))
->add('submit','submit')
->getForm();
$view = $form->createView();
$this->admin->setSubject($object);
$this->get('twig')->getExtension('form')->renderer->setTheme($view, $this->admin->getFormTheme());
return $this->render($this->admin->getTemplate('EDIT'), array(
'action' => 'edit',
'object' => $object,
'form' => $view,
));
}
但是我收到了这个错误:
Impossible to access a key ("default") on a boolean variable ("")
错误来自 twif 文件中的这一行:
{{ form_helper.render_groups(admin, form, admin.formtabs['default'].groups, has_tab) }}
我找不到解决办法,有人知道吗?
【问题讨论】:
-
检查您的
admin变量。看起来formtabs是false而不是数组。可能数组操作失败并返回 false
标签: symfony sonata-admin