Bootstrap Modulation Modules / Scripts in Zend Framework

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

Here is my application structure:

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

I had a problem: styles and scripts loaded via headLink() and headScript in /application/modules/admin/Bootstrap.php are also loaded into my controller / actions that are not in the admin module. Here is my 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'); } 

/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 and why he does it: because I get the view from the master boot record (?). My question is, how does one load specific style modules and / or script files?

I apologize if this is a duplicate question, I was looking for different formulations of the name of the question, and I did not find anything convincing.

Thanks Ken

+7
source share
3 answers

Unable to determine module name at boot time. Only after routeShutdown do you know the name of the module. If you are using a layout, 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 } } } 
+4
source

Boot files for all modules executed for each request.

I can offer to register the front controller plugin from bootstrap and do your conditional magic on preDispatch ().

+1
source

if you use a layout, the easiest way is to add something like the following at the top of the layout page for a specific module:

  $ this-> headLink () -> appendStylesheet ('/ styles / admin / styles_admin.css');
 $ this-> headScript () -> appendFile ('/ scripts / admin / scripts_admin.js'); 
0
source

All Articles