【问题标题】:View overloading in Zend FrameworkZend Framework 中的视图重载
【发布时间】:2009-09-20 17:26:12
【问题描述】:

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

类 ContentController 扩展 Zend_Controller_Action { }

类 NewsController 扩展 ContentController { }

如果没有为新闻控制器找到视图,我希望 Zend 使用其父控制器的脚本路径。 如何在不必路由到其父控制器的情况下实现这一点?

【问题讨论】:

    标签: zend-framework


    【解决方案1】:

    您必须手动添加 scriptPath:

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

    【讨论】:

      猜你喜欢
      • 2012-02-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-06
      • 1970-01-01
      • 2011-06-15
      相关资源
      最近更新 更多