使用Zend 1.7我正在验证一些数据。如果验证失败,我forward
到另一页。
如果输入验证失败,是否可以转发生成的错误消息?
像这样:
public function postAction() {
$newData = $this->getRequest ()->getPost ();
$validators = array ('name' => array ('presence' => 'required'));
$input = new Zend_Filter_Input(null, $validators);
$input->setData($newData);
if (!$input->isValid()) {
print_r($input->getErrors());
print_r($input->getMessages());
//here I want to pass the Erros and the Messages
return $this->_forward('action', 'controller', 'module');
}
}
答案 0 :(得分:1)
forward()
的第四个参数可用于传递参数:
return $this->_forward(
'action',
'controller',
'module',
array(
'errors' => $input->getErrors(),
'messages' => $input->getMessages()
)
);
虽然你不应该通过完全成熟的Zend Framework对象。