How to preload extensions in main application only, not modules

Hi All,

I have preloaded an extension ( foundation ) in application configuration, it works fine.





I have a module ( backend ) loading a css file from that extension.

What I want is to load the extension only for the main application, not the module. What should I do please ?


CModule also has a preload array, you can fill this array for each module (excluding the backend module) with the foundation extension.

Or derive all modules from your own Module class and set there once the preload array with foundation, but let the backend module derive from CModule so that has an empty preload array.

I’m not sure I’m getting you right, but I already used preload in my module loading log only, not foundation.

My BackendModule init() method

public function init()


		// this method is called when the module is being created

		// you may place code here to customize the module or the application

		// import the module-level models and components







                    'preload'=>array( 'log'),


                     // application components










I have only one module, and I don’t want it to load foundation, foundation is preloaded in application configuration ( protected/config/main.php ) so it applies to the whole application and my module even if it’s not

preloaded in module config.

I meant something different, first you shouldn’t load your foundation in the application configuration, but only the log. Load the foundation in your modules. That you can do by creating a Module class which derives from CModule and let all your modules derive from that Module class.In your Module class you can add the foundation to your preload array.

I’m not sure but i guess you can set the preload array as property of the Module class.

Something like this:

class Module extends CModule {

     public $preload = array('foundation');


class AllOtherModules extends Module {


class BackendModule extends CModule {


     //Here you don't have to set the preload array, because the log is preloaded from the application configuration.


Thanks for answering, but you’re not getting me right, your solution suppose I have many modules and I want to load foundation to all of them except Backend, that’s not the problem.

I only have one module ( Backend ), I need to use foundation for the main application not the module. Do you see ?

Sorry for misunderstanding you. I understand your problem no;) i’ve searched around if you can manipulate the preload array in the application configuration…but as far as i can see it’s impossible. What you can do is defining your preload array based on the url.

Something like:

if($_SERVER['REQUEST_URI'] contains 'backend' after index){ //find a good rule for this.

    $preload = array('log');


    $preload = array('log','foundation');


And set this preload array as variable in your application configuration file. I know it’s not the most beautiful solution, but i guess it will work.

Thanks, but preload is made inside the main configuration array, I can’t make conditional statements inside the array.

What happens is that foundation loads a css file in the backend layout, it messes the backend style. Is there a way I can “unload” it ( remove the asset ) before it’s published ?

But you can make a conditional statement before you return your configuration array. And set the $preload variable inside the main configuration array.

What you also can do is change the foundation extension and add the described conditional statement in your init of the Foundation class. Then the foundation won’t register the css and js files.

I’ll try to modify the extension. Thanks !

I found this thread very helpful, and I know it’s quite old at this point, but it doesn’t seem to have a final solution, which I’ll try to provide for others’ reference.

Here’s a simple inline conditional that should selectively preload bootstrap only if “moduleName” is not in the url. Note that if “moduleName” overlaps with other page, controller or model names you’ll need a more complex condition.

return array(


'preload'=>strpos($_SERVER['REQUEST_URI'], 'moduleName') ? array('log') : array('log', 'bootstrap'),