dp198879 2014-01-16 14:30
浏览 40
已采纳

如何在Zend框架中的控制器中设置两个视图

I'm trying to achieve a thank you page after submitting a form in Zend 1.12

in the index i have form and i want if the validation passes then should go to another view (NOT INDEX) for thank you page. how can i do this in my code:

public function indexAction()
{
    // action body
    $C_form = new Application_Form_Eform();
    if ($this->_request->isPost()) {
            $formData = $this->_request->getPost();
            if ($C_form->isValid($formData)) {
            $this->_helper->redirector('','result');
            exit;
            } else {
            $C_form->populate($formData);
            }
            }
    $this->view->form = C_eform;
}

and after that where should i create the .phtml file? in the application\views\scripts\index?

  • 写回答

1条回答 默认 最新

  • douye6812 2014-01-16 14:39
    关注

    I think you're looking for render:

    $this->view->render('index/yourotherview.phtml');
    

    In this case, index/ is referring to your views/scripts/index folder, and the yourotherview.phtml file.

    So, all together it would be:

    public function indexAction()
    {
        // action body
        $C_form = new Application_Form_Eform();
        if ($this->_request->isPost()) {
            $formData = $this->_request->getPost();
            if ($C_form->isValid($formData)) {
                $this->_redirect('/index/result);
            } else {
                $C_form->populate($formData);
            }
        }
        $this->view->form = C_eform;
    }
    

    EDIT:

    From your comment it looks like you just want to be redirected instead of displaying a different view. In this case, it's as easy as creating a new action and making the view for it:

    public function resultAction() {
        // Code here if you need it
    }
    

    Then create the file result.phtml in the index/ views directory, and you'll need $this->_redirect('/index/result'); in the index controller. (See above code)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部