102
Also, if you want to add module assets both CSS and JS, you can use the following logic. See how you need to indicate the correct path to getPathOfAlias:
public static function register($file)
{
$url = Yii::app()->getAssetManager()->publish(
Yii::getPathOfAlias('application.modules.shop.assets.css'));
$path = $url . '/' . $file;
if(strpos($file, 'js') !== false)
return Yii::app()->clientScript->registerScriptFile($path);
else if(strpos($file, 'css') !== false)
return Yii::app()->clientScript->registerCssFile($path);
return $path;
}
The above code has been taken from GPLed Yii based Webshop app.
In Yii framework, You can include js and css using below method.
Including CSS:
{Yii::app()->request->baseUrl}/css/styles.css
Including JS:
{Yii::app()->request->baseUrl}/js/script.js
Including Image:
{Yii::app()->request->baseUrl}/images/logo.jpg
Note: By using layout concept in yii, You can add css and js instead of specifying in view template.
Add the CSS and JS in The Layout Folder.Access anywhere in the project
<!--// Stylesheets //-->
<?php
$themepath=Yii::app()->theme->baseUrl;
Yii::app()->clientScript->registerCoreScript("jquery");
?>
<link href="<?php echo $themepath."/css/custom.css"; ?>" rel="stylesheet" media="all" />
<!--// Javascript //-->
<?php Yii::app()->clientScript->registerCoreScript("jquery"); ?>
</script> -->
<script type="text/javascript" src="<?php echo $themepath; ?>/js/video.min.js"></script>