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?
Yii framework uses “Gii” tool, which is a web-based code scaffolding tool that is used to create code quickly. Using this, we can create templates in models, controllers, forums, modules, extensions, CRUD controlled actions, and views.
Conceptually Yii1 and Yii2 are quite similar, however Yii2 runs on newer PHP versions and utilizes namespaces, traits etc. Yii2 has also support for dependency injection through $container singleton available after initializing the framework.
It helps in reducing the response time and improves the speed and performance of the web application. Yii allows easy integration of a cache application component.
Applications are objects that govern the overall structure and lifecycle of Yii application systems. Each Yii application system contains a single application object which is created in the entry script and is globally accessible through the expression \Yii::$app .
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
).
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.
This would resolve the query as this provides detailed explanation for the assets folder:
http://www.yiiframework.com/wiki/148/understanding-assets/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With