Question

I notice that Yii creates strange set of directories (names like 8523d23 or 10s89b92) in assets directory, and this even happens at runtime. For example, one of my tables got more than 10 records, pagination kicked-in and I got a new files in assets subdirectory named pager.css.

When I move my site from testing to production, should I copy all those, or just create an empty "assets" directory, and it will be filled at runtime?

If I want to add, for example, some new jQuery plugin, how should I proceed?

For example, I wish to add jquery.charcounter.js, do I copy it to assets or to yii/framework/web/js/source? If I do the latter, how do I get this .js file included in HTML page output?

Was it helpful?

Solution

assets should be a writable directory. Yii takes care of assets.

By calling Yii::app()->assetManager->publish() some stylesheets, images, scripts, or even entire directories can be put into a web-visible folder.

pager.css and other non-familiar files are produced by widgets (CLinkPager for example) and other components (such as CClientScript publishes jQuery whenever you need that).

During deployment, this folder should be empty, but it doesn't really matter.

Adding plugins should never be done through framework folders. You can place them either in components dir and publish it runtime if necessary, or into any other convenient visible directory (like as images or css).

Update

To embed jquery.charcounter.js, put it in components directory, then call

Yii::app()->clientScript->registerScriptFile(
    Yii::app()->assetManager->publish(
        Yii::getPathOfAlias('application.components').'/jquery.charcounter.js'
    ),
    CClientScript::POS_END
);

Regarding weird folder names, I firmly believe they are unique hashes (or part of), so they can be differentiated if application uses several extensions.

OTHER TIPS

This would resolve the query as this provides detailed explanation for the assets folder:

http://www.yiiframework.com/wiki/148/understanding-assets/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top