我不明白。这是我的字段集:
<?php
namespace example\Form;
use example\Entity\User;
use example\Entity\Strategy\PasswordStrategy;
use Doctrine\Common\Persistence\ObjectManager;
use DoctrineModule\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;
use Zend\Form\Fieldset;
use Zend\InputFilter\InputFilterProviderInterface;
class UserFieldset extends Fieldset implements InputFilterProviderInterface
{
public function __construct(ObjectManager $objectManager)
{
parent::__construct('user');
$this->add(array(
'name' => 'id',
'type' => 'Zend\Form\Element\Hidden',
));
}
public function getInputFilterSpecification()
{
return array();
}
}
这是我的表格:
<?php
namespace example\Form;
use Doctrine\Common\Persistence\ObjectManager;
use DoctrineModule\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;
use Zend\Form\Form;
use example\Form\UserFieldset;
class UserForm extends Form
{
public function __construct(ObjectManager $objectManager)
{
parent::__construct('user-form');
$userFieldset = new UserFieldset($objectManager);
$userFieldset->setUseAsBaseFieldset(true);
$this->add($userFieldset);
$this->add(array(
'name' => 'submit',
'type' => 'Zend\Form\Element\Submit',
'attributes' => array(
'value' => 'Go',
'id' => 'submitbutton',
),
));
}
}
我的行动:
public function userAction()
{
$objectManager = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
$userForm = new UserForm($objectManager);
return array(
'form' => $userForm
);
}
我的观点:
<?php
$form = $this->form;
$form->setAttribute('action', $this->url('user'));
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formRow($form->get('id'));
echo $this->formRow($form->get('submit'));
echo $this->form()->closeTag();
我的错误:
在表单中找不到名称为 [id] 的元素
为什么?只是提交字段呈现正常,但是一旦我添加了 id 字段,我就会得到一个错误......