views:

1845

answers:

1

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?

+6  A: 

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.

pestaa
So, there are no clear rules about this? What *exactly* would you do to include jquery.charcounter.js if it were a requirement in your project?
Milan Babuškov
Also, care to explain why the funny directory names like 734a23c4?
Milan Babuškov
It creates a hash of the path (which could be a `/very/deep/linking/path`) and publishes to that new directory. This means that the directory structure isn't shown (and more importantly, you can publish assets that aren't normally web accessible). You can also extend the assetManager to automatically compress CSS/JS files (see the cookbook) for you.
Blair McMillan