2013-04-08 82 views
1

我在各个模块目录内引导我的应用程序Zend_Application_Module_Bootstrap。我如何要求首先执行另一个模块引导程序中的资源?如何在Zend Framework 1的另一个模块的引导程序中执行模块引导资源?

// app/modules/user/Bootstrap.php 
class User_Bootstrap extends Zend_Application_Module_Bootstrap 
{ 
    protected function _initUser() 
    { 
    } 
} 

// app/modules/author/Bootstrap.php 
class Author_Bootstrap extends Zend_Application_Module_Bootstrap 
{ 
    protected function _initAuthor() 
    { 
     $this->bootstrap('user'); // Fatal: Resource matching 'user' not found 
    } 
} 
+0

你确实明白,所有引导文件中的所有内容都会被混合在一起并且执行每个请求? ZF1明智的做法是只将资源放入需要执行的引导程序中。我们把很多东西放到引导程序中可能会更好,因为插件或一个条带或另一个条带的助手。对不起,没有足够向下滚动:) – RockyFord 2013-04-10 11:53:13

+0

@RockyFord是的,我想我会坚持插件,并听取routeStartup。我想尽快识别用户,因为那样我会根据他们的角色添加样式表/脚本。你觉得自举中的任何条件逻辑(除了检测环境)是一个坏主意吗? – danronmoon 2013-04-10 12:19:53

+0

如果你需要引导中的东西,那么你需要它。只要意识到潜在的成本。为了根据用户角色加载资源,您可能能够将该特定逻辑合并到ACL插件中(具体取决于您如何执行ACL)。如果您想加载用户资源,您可能需要等待'routeShutdown'或'preDispatch',以便确定用户,不要担心在整个调度循环完成之前不会显示任何内容。 – RockyFord 2013-04-13 11:22:19

回答

0

this thread从ZF1的邮件列表,你可以通过应用引导的模块的资源访问模块,白手起家。

男人,多嘴。这就是我的意思是:

// app/modules/user/Bootstrap.php 
class User_Bootstrap extends Zend_Application_Module_Bootstrap 
{ 
    protected function _initUser() 
    { 
    } 
} 

// app/modules/author/Bootstrap.php 
class Author_Bootstrap extends Zend_Application_Module_Bootstrap 
{ 
    protected function _initAuthor() 
    { 
     $app = $this->getApplication(); // it's actually the application *bootstrap* 
     $app->bootstrap('modules'); 
     $modulesResource = $app->getResource('modules'); 
     $userBootstrap = $modulesResource->user; 
     $userBootstrap->bootstrap('user'); // should be cool 
    } 
} 

在我自己的经验,只要需要超过一个模块被引用的我的模块级资源的一个 - 尤其是引导过程中 - 我只是把该资源最多的引导进入应用程序级别的引导程序。

+0

我觉得这是如此接近。我得到了'$ app-> bootstrap('modules')'的'循环资源依赖'错误,因为它正处于启动过程中,并没有完全运行(我想我试图启动它再次)。如果我发表评论,我无法获取模块资源(返回null)。如果我的脚本正在引导我的模块,我如何获取它的资源? – danronmoon 2013-04-09 11:58:41

+0

在application/configs/application.ini中,除了''frontController.resources.modules [] ='声明之外,你的引导程序中是否有'_initModules()'方法?这可能会导致你的循环依赖错误。 – 2013-04-09 12:55:55

+0

我有'resources.modules = []',并且在我的任何引导程序中都没有_initModules方法。我不认为这会对我的问题产生任何影响,但是我继承了'Zend_Application_Module_Bootstrap'并让我的模块引导程序从该子类延伸。浏览程序,在引发异常之前,我在应用程序引导的$ _started数组中看到''modules'=> true'。 – danronmoon 2013-04-09 13:19:58

相关问题