我正在尝试使用viewRender函数将indexAction中的参数发送到editAction。问题是当调用editAction时,它导致我的$ form认为它已被发布。
public funciton indexAction(){
...
if(isset($_POST['edit'])){
$this->_helper->viewRenderer('edit');
$this->editAction($thingINeed);
}
...
}
public function editAction($thingINeed){
...
if($form->posted){
var_dump('FORM POSTED');
}
...
}
即使我尚未发布表单,也会立即打印“FORM POSTED”。我不确定为什么表单$ form-> posted在初始渲染时设置为true。有没有人知道为什么会这样或者解决这个问题?
答案 0 :(得分:0)
你应该检查你的表格:
$form = new MyForm();
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
if ($form->isValid($formData)) {
echo 'success';
exit;
} else {
$form->populate($formData);
}
}
$this->view->form = $form;
答案 1 :(得分:0)
我不确定你想要获得什么,但为了在两个动作之间传递价值,最好使用_getParam和_setParam方法:
public funciton indexAction(){
...
if(isset($_POST['edit'])){
$this->_setParam( 'posted', true );
$this->_helper->viewRenderer('edit');
//$this->editAction($thingINeed);
// It should be better to use Action stack helper to route correctly your action :
Zend_Controller_Action_HelperBroker::getStaticHelper( 'actionStack' )->actionToStack( 'edit' );
} else {
$this->_setParam( 'posted', false );
}
...
}
// param $thingINeed is not "needed" anymore
public function editAction(){
...
if( true == $this->_getParam( 'posted' ) {
var_dump('FORM POSTED');
}
...
}