Managing assets
An ability to manage assets is one of the greatest parts of Yii. It is especially useful in the following cases:
When you want to implement an extension that stores its JavaScript, CSS, and images in its own folder that is not accessible from a browser
When you need to pre-process your assets: combine JavaScript, compress it, and so on
When you use assets multiple times per page and want to avoid duplicates
While the first two cases could be considered as bonuses, the third one solves many widget reusing problems.
Let's create a simple widget using sample API, which will publish and use its own CSS, JavaScript, and an image.
Getting ready
Create a fresh Yii application using
yiic webappas described in the official guide.Check that the
assetsdirectory under application'swebroot(whereindex.phpis) has write permissions; assets will be written there.Generate and download a preloader image from http://ajaxload.info/.
How to do it...
Let's do some planning first. In Yii, you can place...