I'm trying to use Zend Framework 2 formBuilder with annotations in my model, but it's throwing an exception when trying to render a checkbox:
Model property annotation:
/**
* @var boolean $Content
*
* @ORM\Column(name="Content", type="boolean", nullable=false)
* @Annotation\Attributes({"type":"checkbox"})
* @Annotation\Options({"label":"Value:"})
* @Annotation\AllowEmpty({"true"})
* @Annotation\Filter({"name":"Boolean"})
*/
protected $Content = true;
HTML from form template (phtml)
<div id="Content">
<?= $form->get('Content)->getLabel(); ?>
<?= $this->formCheckbox($form->get('Content)); ?>
</div>
When it tries to run the formCheckbox, it is throwing
PHP Fatal error: Uncaught exception 'Zend\\Form\\Exception\\InvalidArgumentException' with message 'Zend\\Form\\View\\Helper\\FormCheckbox::render requires that the element is of type Zend\\Form\\Element\\Checkbox' in /media/finaoweb/doctrine-test/vendor/zendframework/zend-form/src/View/Helper/FormCheckbox.php:29
Stack trace:
#0 /media/finaoweb/doctrine-test/vendor/zendframework/zend-form/src/View/Helper/FormInput.php(101): Zend\\Form\\View\\Helper\\FormCheckbox->render(Object(Zend\\Form\\Element))
#1 [internal function]: Zend\\Form\\View\\Helper\\FormInput->__invoke(Object(Zend\\Form\\Element))
#2 /media/finaoweb/doctrine-test/vendor/zendframework/zend-view/src/Renderer/PhpRenderer.php(393): call_user_func_array(Object(Zend\\Form\\View\\Helper\\FormCheckbox), Array)
#3 /media/finaoweb/doctrine-test/module/Application/view/application/itemoption/edititemoption.phtml(34): Zend\\View\\Renderer\\PhpRenderer->__call('formCheckbox', Array)
Looking at the stack trace before the formCheckbox() call, I can see the element attributes including 'type => "checkbox"'
I have even tried changing 'checkbox' to \Zend\Form\Element\Checkbox and Zend\\Form\\Element\\Checkbox with no luck.
Any help is appreciated.
Aucun commentaire:
Enregistrer un commentaire