dp198879 2014-01-16 22: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 22: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)

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

报告相同问题?

悬赏问题

  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题