drlu11748 2012-04-01 01:42
浏览 45
已采纳

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

I am trying to load specific styles/script resources for a specific module within my application.

Here is my application structure:

-application
  -configs
  -controllers
  -forms
  -layouts
  -models
  -modules
    -admin
      -configs
      -controllers
      -models
      -views
      -Bootstrap.php
  -views
  -Bootstrap.php

The problem I'm having is: the styles and scripts I am loading through headLink() and headScript in /application/modules/admin/Bootstrap.php are also being loaded in my controller/actions that are not in the admin module. Here are my Bootstrap.php's

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

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

I can see how or maybe why it's doing it: because I'm getting the view from the main bootsrap(?). My question is, how does one load module specific stylesheets and/or script files?

I apologize if this is a duplicate question, i searched for various wordings of the title of the question and I didn't find anything conclusive.

Thanks, Ken

  • 写回答

3条回答 默认 最新

  • dongzang7182 2012-04-01 02:37
    关注

    Its not possible to determine name of module at bootstrap time . Only after routeShutdown you will come to know about module name . If you are using layout then open application.ini

    resources.layout.pluginClass = "My_Layout_Controller_Plugin_Layout"
    

    inside

    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
    }
    }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 vue3 + vite + electron打包找不到第三方包?
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点