如何在 Zend 框架中的控制器中设置两个视图 [英] How to set two views in a controller in Zend framework
问题描述
在 Zend 1.12 中提交表单后,我正在尝试实现感谢页面
在索引中我有表单,如果验证通过,我希望应该转到另一个视图(不是索引)以获取感谢页面.我怎么能在我的代码中做到这一点:
公共函数 indexAction(){//动作主体$C_form = new Application_Form_Eform();如果 ($this->_request->isPost()) {$formData = $this->_request->getPost();如果 ($C_form->isValid($formData)) {$this->_helper->redirector('','result');出口;} 别的 {$C_form->populate($formData);}}$this->view->form = C_eform;}
然后我应该在哪里创建 .phtml 文件?在应用程序\视图\脚本\索引中?
我认为您正在寻找 渲染:
$this->view->render('index/yourotherview.phtml');
在这种情况下,index/
指的是您的 views/scripts/index
文件夹和 yourotherview.phtml
文件.>
所以,总而言之:
公共函数 indexAction(){//动作主体$C_form = new Application_Form_Eform();如果 ($this->_request->isPost()) {$formData = $this->_request->getPost();如果 ($C_form->isValid($formData)) {$this->_redirect('/index/result);} 别的 {$C_form->populate($formData);}}$this->view->form = C_eform;}
从您的评论来看,您似乎只想被重定向而不是显示不同的视图.在这种情况下,就像创建一个新操作并为其创建视图一样简单:
公共函数 resultAction() {//如果需要,请在此处编码}
然后在 index/
视图目录中创建文件 result.phtml
,您将需要 $this->_redirect('/index/result');
在索引控制器中.(见上面的代码)
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?
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)
这篇关于如何在 Zend 框架中的控制器中设置两个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!