Working with AssetManager


I writing the widget and I need to publish some files. It’s the folder with the images, one css file and one javascript file. My directory widget structure is:

- extensions

---- mywidget

--------- assets

------------- js

----------------- js.js

------------- css

----------------- css.css

------------- images

----------------- many images here

----------- views

--------------- index.php

--------- MyWidget.php

Firstly I tried to puslish these files just like this:


This works fine, but I tired of permanent removing the asset directory when I change css or js files.

Then I decide to publish this stuff separately.

Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('ext.mywidget.assets') . '/js/mywidget.js');

Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('ext.mywidget.assets') . '/css/mywidget.css');


This time it works not fine. Images, css file and js file have finded in different asset folders.

So how can I publish these files in one asset directory?

I know that the files are published with a hashed name of the file if it’s a file or the directory name if it’s a directory. What you can try is set a boolean value true as the second parameter in the publish() method. Take a look at:

Thanks for reply pal. But it still doesn’t work.

Yii::app()->assetManager->publish(Yii::getPathOfAlias('ext.widget.assets.images'), true);

Yii::app()->assetManager->publish(Yii::getPathOfAlias('ext.widget.assets') . '/js/widget.js', true);

Yii::app()->assetManager->publish(Yii::getPathOfAlias('ext.widget.assets') . '/css/widget.css', true);

Three folders created as before.

publish the entire directory of assets

Doesn’t work. Old files are not replaced

setting the last paramater in the function call should accomplish what u want


You probably need to copy the file from the svn as the option is not available in version 1.1.1 and lower

I’m sorry, where did you get that information? I see last release of yii is 1.1.1, and I don’t know where I can download the 1.1.2 version. In 1.1.1 version fourth parameter is missed:

public string publish(string $path, boolean $hashByName=false, integer $level=-1)

You have to check out the code using an svn client.

You could use YII_DEBUG for that flag. So your assets folder is always up to date when debugging:


You’ll have to wait for 1.1.2 for that to work, of course. My guess is, that realease is around the corner.