Include CSS,javascript file in Yii Framework


Question

How to include a Javascript or CSS file in Yii Framework?

I want to create a page on my site that has a little Javascript application running, so I want to include .js and .css files in a specific view.

1
96
7/2/2015 1:05:00 PM

Accepted Answer

Something like this:

<?php  
  $baseUrl = Yii::app()->baseUrl; 
  $cs = Yii::app()->getClientScript();
  $cs->registerScriptFile($baseUrl.'/js/yourscript.js');
  $cs->registerCssFile($baseUrl.'/css/yourcss.css');
?>
165
1/20/2010 7:52:22 PM

You can do so by adding

Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/path/to/your/script');

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon