简体   繁体   中英

Yii not automatically publishing assets on change

I'm working on a Yii project, using a remote Ubuntu webserver for development.

I've changed a Javascript file that I publish through AssetManager. The file has been uploaded to the webserver, but AssetManager has not detected the new file and republished the asset.

The standard advice is to delete the contents of the asset folder - but if I delete the already published version of the file, it doesn't replace it - I just get a file not found error in the browser.

I'm guessing I've got some permissions wrong somewhere, but (as it's a dev server) even chmodding to 777 doesn't fix this - anyone got an idea how I get AssetManager to recognise the change in the asset?

AssetManager code below:

$assetFolder = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('alias.path.to.folder'));
Yii::app()->clientscript->registerScriptFile($assetFolder.'/assetname.js');

Try publish your file this way:

$cs = Yii::app()->clientScript;
$cs->registerScriptFile(Yii::app()->getAssetManager()->publish('path/to/file.js'));

This function automatically publish file to assets folder if it was changed and add <script> tag to your HTML with appropriate path to script file from assets folder.

If you are trying to publish a folder, the assetManager will not follow the changes in the files in this folder and publish it only once. Or you can pass parameter $forceCopy in publish() function for republishing folder each time.

http://www.yiiframework.com/doc/api/1.1/CAssetManager#publish-detail

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM