我想为我的应用程序创建一个带有 Zend Framework 2 的表单,我已经准备好了所有内容,并且表单正在显示,但我的问题是我无法绑定来自数据库的初始表单值
$myUserDetails = <details of my user coming from DB>;
$form = $form->bind($myUserDetails); //This should set the values for the form to display but it doesnt
我的显示逻辑很简单如下图
$form = $this->form;
$form->setAttribute('action',
$this->url('<routename>',array('action'=>'<actionname>')));
$form->prepare();
echo $this->form()->openTag($form) . PHP_EOL;
echo $this->formRow($form->get('email_id')) . PHP_EOL;
echo $this->formRow($form->get('dob')) . PHP_EOL;
echo $this->formRow($form->get('gender')) . PHP_EOL;
echo $this->formRow($form->get('user_page_name')) . PHP_EOL;
echo $this->formInput($form->get('submit')) . PHP_EOL;
echo $this->form()->closeTag($form) . PHP_EOL;
现在我尝试在我的控制器操作中设置绑定到表单的对象中的数据
$myUserDetails = <details of my user coming from DB>;
$form = $form->bind($myUserDetails);
$data = $myUserDetails->getArrayCopy();
$form->setData($data['data']);
这似乎以某种方式起作用,并且在视图中显示了我的值。所以我只想知道我在第一种方法中做错了什么?提前致谢 :)