简体   繁体   English

Yii不会在更改时自动发布资产

[英]Yii not automatically publishing assets on change

I'm working on a Yii project, using a remote Ubuntu webserver for development. 我正在使用一个远程Ubuntu网络服务器进行开发的Yii项目。

I've changed a Javascript file that I publish through AssetManager. 我已经更改了通过AssetManager发布的Javascript文件。 The file has been uploaded to the webserver, but AssetManager has not detected the new file and republished the asset. 该文件已上传到Web服务器,但是AssetManager尚未检测到新文件并重新发布资产。

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? 我猜我某个地方的权限有误,但是(因为它是开发服务器)即使更改为777也不能解决此问题-有人知道我如何让AssetManager识别资产的变化吗?

AssetManager code below: 下面的AssetManager代码:

$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. 如果文件被更改,此功能会自动将文件发布到assets文件夹,并使用assets文件夹中脚本文件的适当路径将<script>标记添加到HTML。

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. 如果您尝试发布文件夹,assetManager将不会遵循此文件夹中文件的更改,而只会发布一次。 Or you can pass parameter $forceCopy in publish() function for republishing folder each time. 或者,您可以在publish()函数中传递参数$ forceCopy来每次重新发布文件夹。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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