Hi!
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:
Yii::app()->assetManager->publish(Yii::getPathOfAlias('ext.mywidget.assets'));
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');
Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('ext.mywidget.assets.images'));
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?
Vince
(Vadimg88)
April 25, 2010, 7:45pm
2
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: http://www.yiiframework.com/doc/api/CAssetManager#publish-detail
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.
jayrulez
(Waprave)
April 25, 2010, 9:55pm
4
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
jayrulez
(Waprave)
April 25, 2010, 10:51pm
6
setting the last paramater in the function call should accomplish what u want
CAssetManager::publish($path,$hashByName=false,$level=-1,$forceCopy=false);
* @param boolean whether we should copy the asset file or directory even if it is already published before.
* This parameter is set true mainly during development stage when the original
* assets are being constantly changed. The consequence is that the performance
* is degraded, which is not a concern during development, however.
* This parameter has been available since version 1.1.2.
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)
jayrulez
(Waprave)
April 26, 2010, 1:30am
8
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)
http://code.google.com/p/yii/
You have to check out the code using an svn client.
mikl
(Mike)
April 26, 2010, 7:40am
9
You could use YII_DEBUG for that flag. So your assets folder is always up to date when debugging:
Yii::app()->assetManager->publish(Yii::getPathOfAlias('ext.mywidget.assets'),false,1,YII_DEBUG);
You’ll have to wait for 1.1.2 for that to work, of course. My guess is, that realease is around the corner.