脚本宝典收集整理的这篇文章主要介绍了php – Zend Framework _forward到同一控制器内的其他动作,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
例:
如果我指向用户控制器默认操作是indexAction()在这个函数内我使用_forwad(‘list’)…但是所有的调度过程都重复了…我不这样做
什么是正确的方法?
// inside your controller... public function indexAction() { $this->_helPEr->vieWrenderer('foo'); // the name of the action to render instead $this->fooAction(); // call foo action Now }
如果您经常使用这个“技巧”,也许您可以编写一个在应用程序中扩展的基本控制器,它可以简单地使用如下方法:
abstract class My_Controller_Action extends Zend_Controller_Action { PRotected function _doAction($action) { $method = $action . 'Action'; $this->_helper->vieWrenderer($action); return $this->$method(); // yes,this is valid PHP } }
class Default_Controller extends My_Controller_Action public function indexAction() { if ($someCondITion) { return $this->_doAction('foo'); } // execute normal code here for index action } public function fooAction() { // foo action goes here (you may even call _doAction() again...) } }
以上是脚本宝典为你收集整理的php – Zend Framework _forward到同一控制器内的其他动作全部内容,希望文章能够帮你解决php – Zend Framework _forward到同一控制器内的其他动作所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。