Zend Framework 中的视图重载 [英] View overloading in Zend Framework

查看:29
本文介绍了Zend Framework 中的视图重载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有 2 个控制器,内容和新闻:

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

class ContentController 扩展 Zend_Controller_Action { }

class ContentController extends Zend_Controller_Action { }

class NewsController 扩展 ContentController { }

class NewsController extends ContentController { }

如果没有找到新闻控制器的视图,我希望 Zend 使用其父控制器的脚本路径.如何在无需路由到其父控制器的情况下实现此目的?

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?

推荐答案

您必须手动添加 scriptPath:

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');
   }

}

class NewsController extends ContentController {

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

这将使用视图脚本变形器的堆栈功能.它将首先查看最后指定的路径,即 APPLICATION_PATH .'/views/scripts/news',如果在那里找不到脚本,它将在堆栈上的第二个目录中查找,即 APPLICATION_PATH .'/views/scripts/content'.

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'.

这篇关于Zend Framework 中的视图重载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆