How to set two views in a controller in Zend framework

老子叫甜甜 提交于 2019-12-11 21:25:38

问题


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:


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)



来源:https://stackoverflow.com/questions/21174276/how-to-set-two-views-in-a-controller-in-zend-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!