Module assets (css, js, etc..)


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 ?


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

(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

It adds its module assets like:

public static function register($file)


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


    $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.