Include CSS,javascript file in Yii Framework

viji picture viji · Jan 4, 2010 · Viewed 108.6k times · Source

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.

Answer

Alexander Hramov picture Alexander Hramov · Jan 13, 2010

Something like this:

<?php  
  $baseUrl = Yii::app()->baseUrl; 
  $cs = Yii::app()->getClientScript();
  $cs->registerScriptFile($baseUrl.'/js/yourscript.js');
  $cs->registerCssFile($baseUrl.'/css/yourcss.css');
?>