I. The role of YII assets:
The role of assets in 1.YII is to facilitate modularity, plug-ins, and generally for security reasons do not allow access to the protected files below the URL , but we also want to separate module out, so we need to use the publication, Make a copy of the file under a directory to assets for easy access via URL
$assets = Yii::getpathofalias (' ext '). ' /css ';
$BASEURL = Yii::app ()->getassetmanager ()->publish ($assets);
$BASEURL = Yii::app ()->assetmanager->publish ($assets); EXTENSIONS/CSS publishes to assets
Yii::app ()->clientscript->registercssfile ($baseUrl. ') under the creation of a randomly conflicting folder. /main.css ');//Refer to Main.css below assets
2. If a module needs to add use resources, it can be added directly from the Webroot reference.
But trying to create a module can be referenced anywhere, and resources are independent and can avoid naming conflicts .
How do you guarantee that your file name does not conflict with a file with the same name as an attempt by some scattered applications, as is the case for JS,IMAGES,CSS.
by Cassetmanager,yii::app ()->assetmanager can automatically publish private resources to the public directory Webroot/assets
second, the use of examples:
The following is an example of admin module to illustrate the use of assets:
1, the need to use the resources under the modules/admin/assets.
2, through Cassetmanager,yii::app ()->assetmanager can automatically publish the private resources to the public directory site Directory/assets
3. Yii will automatically create a randomly/assets folder under the Site directory, such as 2b31b42b, and copy the files in your modules/admin/assets directory.
Get the following code, modify the protected\modules\admin\adminmodule.php file,
<?php
class Adminmodule extends Cwebmodule
{
private $_assetsurl;
Public Function Getassetsurl ()
{
if ($this->_assetsurl===null)
$this->_assetsurl=yii::app ()- >getassetmanager ()->publish (Yii::getpathofalias (' application.modules.admin.assets '));
return $this->_assetsurl;
}
Public Function Setassetsurl ($value)
{
$this->_assetsurl= $value;
}
}
Then, using $this->module->assetsurl in/protected/modules/admin/views/layouts/main.php can call your CSS and other files, the code looks like this:
<link rel= "stylesheet" type= "Text/css" href= "<?php echo $this->module->assetsurl;? >/css/screen.css" Rel= "External nofollow"/>
You also need to force an update asset before you use the code as follows:
$BASEJSURL = Yii::app ()->getassetmanager ()->publish ($baseJsPath, False,-1, yii_debug);