Zend Framework中的Bootstrapping模块特定样式/脚本

Ken*_*Ken 7 javascript css php zend-framework module

我正在尝试为我的应用程序中的特定模块加载特定样式/脚本资源.

这是我的应用程序结构:

-application
  -configs
  -controllers
  -forms
  -layouts
  -models
  -modules
    -admin
      -configs
      -controllers
      -models
      -views
      -Bootstrap.php
  -views
  -Bootstrap.php
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是:我通过加载样式和脚本headLink(),并headScript/application/modules/admin/Bootstrap.php也被在我的控制器/是行动装admin模块.这是我Bootstrap.php

/application/Bootstrap.php:

protected function _initDoctype()
{
    $this->_logger->info('Bootstrap ' . __METHOD__);

    //init the view
    $this->bootstrap('view');
    $view = $this->getResource('view');
    $view->doctype('XHTML1_STRICT');

    //Set title and separator
    $view->headTitle('Sunny Rose Photography')
         ->setSeparator(' | ');

    //Load global stylesheets
    $view->headLink()->appendStylesheet('/styles/styles_main.css')
         ->headlink()->appendStylesheet('/scripts/jquery-ui-1.8.17/themes/base/jquery-ui.css');

    //Load Scripts
    $view->headScript()->prependFile('/scripts/jquery-1.7.1/jquery-1.7.1.js')
         ->headScript()->appendFile('/scripts/jquery-ui-1.8.17/ui/minified/jquery-ui.min.js')
         ->headScript()->appendFile('/scripts/gallery.js')
         ->headScript()->appendFile('/scripts/scripts_main.js');
}
Run Code Online (Sandbox Code Playgroud)

/application/modules/admin/Bootstrap.php:

 protected function _initDoctype()
{
    $this->bootstrap('view');
    $view = $this->getResource('view');
    $view->headLink()->appendStylesheet('/styles/admin/styles_admin.css');
    $view->headScript()->appendFile('/scripts/admin/scripts_admin.js');
}
Run Code Online (Sandbox Code Playgroud)

我可以看到它是如何或者为什么这样做的:因为我从主要的bootsrap(?)获得了视图.我的问题是,如何加载模块特定的样式表和/或脚本文件?

如果这是一个重复的问题我道歉,我搜索了问题标题的各种措辞,我没有找到任何结论.

谢谢,肯

Mr *_*der 4

不可能在引导时确定模块的名称。只有在routeShutdown之后你才会知道模块名称。如果您使用布局,则打开 application.ini

resources.layout.pluginClass = "My_Layout_Controller_Plugin_Layout"
Run Code Online (Sandbox Code Playgroud)

里面

class My_Layout_Controller_Plugin_Layout extends Zend_Layout_Controller_Plugin_Layout
{

public function routeShutdown($request)
{
   $moduleName = $request->getModuleName();

if($moduleName == 'admin') 
{
// load css , js for this specific module
}
}
}
Run Code Online (Sandbox Code Playgroud)