View overloading in Zend Framework

余生长醉 提交于 2019-12-24 11:48:05

问题


Let's say I have 2 controllers, content and news:

class ContentController extends Zend_Controller_Action { }

and

class NewsController extends ContentController { }

If there are no views found for the news controller, I want Zend to use the scripts path of its parent controller. How can I achieve this without having to route to its parent controller?


回答1:


You will have to add the scriptPath manually:

class ContentController extends Zend_Controller_Action { 

   public function init()
   {
      $this->view->addScriptPath(APPLICATION_PATH . '/views/scripts/content');
   }

}

and

class NewsController extends ContentController {

   public function init ()
   {
       // Ensure that ContentController inits.
       parent::init();
      $this->view->addScriptPath(APPLICATION_PATH . '/views/scripts/news');
   }
}

This will use the stack functionality of the view script inflector. It will first look in the path last specified, which is APPLICATION_PATH . '/views/scripts/news', if the script isn't found there, it will look in the second directory on the stack, which is APPLICATION_PATH . '/views/scripts/content'.



来源:https://stackoverflow.com/questions/1451514/view-overloading-in-zend-framework

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