Module assets (css, js, etc..)

Hello,

I’ve created a couple of modules for my web application, I’ve set the respective layout for each module

and all is good.

My problem is that I want to create a directory structure in each module having for example

/protected/modules/MODULENAME/css and /protected/modules/MODULENAME/js in order to keep each

module’s css and js files under their directory…

I can’t seem to figure out a way to declare the correct path of the css or js when I try to load

it in my view file. Does anyone have any idea ?

thanks

You can use Yii::getPathOfAlias to resolve your modules path:

http://www.yiiframework.com/doc/api/YiiBase#getPathOfAlias-detail

(And then publish it using AssetManager)

thanks it worked fine :)

The above solution didn’t work for me quite well. So I kept searching and found this nice Yii based Webshop app http://code.google.com/p/yii-shop/source/browse/trunk/models/Shop.php?spec=svn15&r=15.

It adds its module assets like:




public static function register($file)

{

    $url = Yii::app()->getAssetManager()->publish(

    Yii::getPathOfAlias('application.modules.shop.assets.css'));


    $path = $url . '/' . $file;

    if(strpos($file, 'js') !== false)

        return Yii::app()->clientScript->registerScriptFile($path);

    else if(strpos($file, 'css') !== false)

        return Yii::app()->clientScript->registerCssFile($path);


    return $path;

}



It made the trick.