fool-dev
fool-dev

Reputation: 7777

Include JS Files on Yii

I have a question how can i include JS files on Yii, I can not use the default JS or jquery script from Yii.

I have trying to this code-

<link rel="javascript" type="text/javascript" href="<?php echo Yii::app()->request->baseUrl; ?>/js/panel.js" />

Upvotes: 1

Views: 2913

Answers (3)

rahul sharma
rahul sharma

Reputation: 111

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

Upvotes: 0

Mohsen
Mohsen

Reputation: 1422

this is what you want:
add this in view file in yii it will add js file after jquery ui

$this->registerJsFile(Yii::$app->request->baseUrl . '/js/yourjs.js', ['depends' => [\frontend\assets\JqueryUiAsset::className()]]);

Upvotes: 0

charlietfl
charlietfl

Reputation: 171669

Javascript goes in a <script> tag not a <link> tag

Try:

<script src=<?php echo Yii::app()->request->baseUrl; ?>/js/panel.js"></script>

Upvotes: 1

Related Questions