我在Zend框架手册
中关注此示例http://framework.zend.com/manual/en/zend.form.forms.html
我遇到从子表单中取出所有值的问题,因此我可以将值存储到模型(数据库)
以下是处理表单的操作(在Zend框架手册示例中,它仅显示使用getSessionNamespace显示视图中的所有值)
public function processAction()
{
if (!$form = $this->getCurrentSubForm()) {
return $this->_forward('index');
}
if (!$this->subFormIsValid($form,
$this->getRequest()->getPost())) {
$this->view->form = $this->getForm()->prepareSubForm($form);
return $this->render('index');
}
if (!$this->formIsValid()) {
$form = $this->getNextSubForm();
$this->view->form = $this->getForm()->prepareSubForm($form);
return $this->render('index');
}
// Valid form!
// Render information in a verification page
$this->view->info = $this->getSessionNamespace();
$this->render('verification');
}
}
提前非常感谢!
目前我这样做是为了获取所有子表单值(我有2个子表单,一个名为jobDescription,另一个称为userDetail)
private function objectToArray($object)
{
$array=array();
foreach($object as $member=>$data)
{
$array[$member]=$data;
}
return $array;
}
$values = $this->objectToArray($this->getSessionNamespace()); // get all the stored values in the session and convert it to array
$data = array_merge($values['jobDescription'], $values['userDetail']); // merging it together
但我不知道这是获取模型数据的正确方法。
因为我必须在Model类中进行更改,以使其正常工作。
$data = array(
'quoteTypeId' => 1, //
'serviceTypeId' => $values['jobDescription']['serviceType'],
'religionTypeId' => $values['jobDescription']['religionType'],
'postcodeId' => $postcodeId,
'customerComment' => $values['userDetail']['customerComment'],
'contactEmail' => $values['userDetail']['contactEmail'],
'contactFirstName' => $values['userDetail']['contactFirstName'],
'contactLastName' => $values['userDetail']['contactLastName'],
'contactPhoneNumber' => $values['userDetail']['contactPhoneNumber'],
'quoteStatusId' => 0, // Quote Status in Pending Status
'ipAddress' =>$_SERVER['REMOTE_ADDR'],
'createdDate' => $date
);