zend框架动作堆栈需要帮助

时间:2012-05-11 07:45:16

标签: php zend-framework request

我在ZF应用程序中使用action stack。我将在这里解释一下情景。在第一个操作中,我有一个简单的表单与选择框和提交按钮。现在发布帖子我验证数据并保存并在action stack中推送我的第二个操作。

我在堆栈中推送的第二个操作也有一个将在post上保存数据的表单。

现在出现问题:当处理动作堆栈时,它会弹出堆栈并转发存储在堆栈中的第二个动作。现在当我的第二个动作被调用时,它会直接进入post中的循环并尝试验证数据,因为第一个动作请求是post,而我没有从第二个动作获得该表单。

我知道动作堆栈是邪恶的,但截至目前我没有其他选择。这只是我试图解释我的问题的一种情况。

如果我无法正确解释问题,我会很高兴详细解释......

public function firstactionAction() {
    if($this->getRequest()->isPost()) {
        //validate and save form
        $helper = Zend_Controller_Action_HelperBroker::getStaticHelper('actionStack');
        $request = new Zend_Controller_Request_Http();
        $request->setControllerName('index');
        $request->setModuleName('default');
        $request->setActionName('secondaction');
        $helper->pushStack($request);
    } else {
        //creating form object and assigning to view.
    }
}
public function secondactionAction() {
    if($this->getRequest()->isPost()) {
        //Problem is here.. when action stack gets processed.. it directly comes here. as it uses forward internally..
    } else {
        //creating form object and assigning to view.
    }
}

提前感谢...

1 个答案:

答案 0 :(得分:1)

我看到一种简单的方法:只需在每个表单中添加一个简单的隐藏字段,然后执行下一个条件:

if($this->getRequest()->isPost() && $this->getRequest()->getPost('hidden') == 'second_form') {
    // ...
}