0
这里是应该实际发送形式的数据到数据库中, 的方法,但我想不出为什么它不work.There没有错误显示出来,但数据未插入表。如果你能帮助我,我会很高兴!ZendFramework2发布形式
//method to add data to the database
public function addAction() {
//add user info
$form = new UserForm();
$form->get('submit')->setValue('add new info');
$request = $this->getRequest();
if($request->isPost()){
$user = new User();
$form->setData($request->getPost());
if($form->isValid()){
$user->exchangeArray($form->getData());//method that gets the validated data
$this->getUserTable()->saveUser($user);
return $this->redirect()->toRoute('application',array(
'controller'=>'user',
'action'=>'index'
));
}
}
//pass it to the view
$values = array('form'=>$form);
$view = new ViewModel($values);
return $view;
}
意见add.phtml
$form = $this->form;
$form->setAttribute('action', $this->url(
'application', array(
'controller' => 'user',
'action' => 'add',
)
));
echo $this->form()->openTag($form);
echo $this->formHidden($form->get('id'));
echo $this->formRow($form->get('name'));
echo $this->formRow($form->get('email'));
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();
?>