Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Zend framework 特定于模块的布局插件用作.ini资源,但在引导文件中注册时不起作用_Zend Framework - Fatal编程技术网

Zend framework 特定于模块的布局插件用作.ini资源,但在引导文件中注册时不起作用

Zend framework 特定于模块的布局插件用作.ini资源,但在引导文件中注册时不起作用,zend-framework,Zend Framework,我目前正在为每个模块加载不同的布局文件 我已将以下内容添加到我的config.ini文件中 ; Module Support resources.frontController.moduleDirectory = APPLICATION_PATH "/modules" ; Module-based Layout Support resources.layout.pluginClass= "Layout_Plugin_ModuleLayout" 以及以下控制器插件: class Layout_

我目前正在为每个模块加载不同的布局文件

我已将以下内容添加到我的config.ini文件中

; Module Support
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"

; Module-based Layout Support
resources.layout.pluginClass= "Layout_Plugin_ModuleLayout"
以及以下控制器插件:

class Layout_Plugin_ModuleLayout extends Zend_Layout_Controller_Plugin_Layout {    

    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        $this->getLayout()->setLayoutPath(
            Zend_Controller_Front::getInstance()
                ->getModuleDirectory($request->getModuleName()) . '/layouts'
        );
        $this->getLayout()->setLayout('layout');
    }   
}
一切正常,但我更愿意将这个插件和其他插件一起注册到引导文件中。当我将此插件移动到引导文件并按如下方式注册时:

 protected function _initLayouts() {
   $front = Zend_Controller_Front::getInstance();
   $front->registerPlugin(new Layout_Plugin_ModuleLayout());
 }
我得到以下错误:

致命错误:在第31行的C:\workarea\web\u projects\gam\trunk\website\library\Layout\Plugin\ModuleLayout.php中对非对象调用成员函数setLayoutPath()

显然,我做错了什么,或者误解了这个插件的工作原理


编辑:最终在上使用了解决方案的修改版本。不过,我愿意接受有关这方面的建议。这个解决方案使用一个普通的控制器插件,而我怀疑我应该让我们使用布局插件类型。但是,它是有效的。

问题是布局资源初始化了几件事,如果您查看Zend_layout_Controller_Plugin_layout的源代码,您需要传递要使用的布局,因此您可能需要在引导过程中执行以下操作:

protected function _initLayouts()
{
     $this->bootstrap('layout');
     $this->bootstrap('frontController');
     $layout = $this->getResource('layout');

     $front = $this->getResource('frontController');
     $front->registerPlugin(new Layout_Plugin_ModuleLayout($layout));
}

最终在使用了该解决方案的修改版本。

谢谢Chris,我试过了,但它产生了一个循环资源依赖错误。是的,我现在明白了,我认为您编辑的aproach是正确的,我个人使用控制器插件根据模块切换布局,所以我认为这是正确的方法。我总是使用一个标准插件,我认为这是一个非常标准的方法。plugin
Zend\u Layout\u Controller\u plugin\u Layout
主要是一个框架级类,它与调度周期挂钩,并允许将特定于控制器的视图内容注入到布局脚本中。它并不是我们应用程序特定插件的扩展点。