我正面臨編輯我的實體類別值的錯誤。這裏是我的代碼zf2 doctrine2 editAction
<a href="<?php echo $this->url('application/default', array('action'=>'edit','id' => $child->getId()));?>">Bearbeiten</a>
在我的IndexController是動作:
public function editAction()
{
$id = (int) $this->params()->fromRoute('id');
$em = $this->getEntityManager();
$category = $em->getRepository('Application\Entity\Category')->find($id);
$form = new CategoryForm();
$form->setHydrator(new CategoryHydrator());
$form->bind($category);
$request = $this->getRequest();
if($request->isPost())
{
$form->setData($this->getRequest()->getPost());
if($form->isValid())
{
$object = $form->getData();
$category->setName($object->getName());
$category->setDescription($object->getDescription());
$category->setParent($object->getParent());
$em->flush();
return $this->redirect()->toRoute('home');
}
}
return array(
'form' => $form
);
}
這裏是我的CategoryForm.php:
namespace Application\Form;
use Zend\Form\Form;
class CategoryForm extends Form
{
public function __construct()
{
parent::__construct('categoryForm');
$this->setAttribute('method', 'post');
$this->add(array(
'name' => 'name',
'attributes' => array(
'type' => 'text',
'id' => 'name',
),
'options' => array(
'label' => 'Ihr Name:',
),
));
$this->add(array(
'name' => 'description',
'attributes' => array(
'type' => 'text',
'id' => 'description',
),
'options' => array(
'label' => 'Ihre Beschreibung:',
),
));
$this->add(array(
'name' => 'parent',
'attributes' => array(
'id' => 'parent',
'name' => 'parent',
'type' => 'hidden',
),
));
$this->add(array(
'name'=>'submit',
'attributes'=>array(
'type' => 'submit',
'value' => 'OK',
),
));
}
}
而下面是我edit.phtml:
<?php
$form = $this->form;
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formRow($form->get('name'));
echo $this->formRow($form->get('description'));
echo $this->formRow($form->get('parent'));
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();
?>
通過調用動作'編輯',瀏覽器顯示錯誤消息:
Object provided to Escape helper, but flags do not allow recursion
有人知道我的錯誤,可以幫助我嗎?