Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii is not auto including jquery

Tags:

jquery

php

yii

I have a strange problem with Yii & Jquery:

When I open a page which uses ajax/jquery on localhost Yii does automatically add asset include calls to the of the page:

<link rel="stylesheet" type="text/css" href="/PATH/assets/f72b359d/style.css" />
<script type="text/javascript" src="/PATH/assets/2e442e1a/jquery.js"></script>
<script type="text/javascript" src="/PATH/assets/2e442e1a/jquery.cookie.js"></script>

However when I run same code on the server Yii does not do it hense no Jquery available.

I'd appreciate if someone could direct to a way to solve it.

like image 706
Alexei Tenitski Avatar asked Apr 12 '12 11:04

Alexei Tenitski


1 Answers

It seems like you're not registering jQuery in the correct way. You must add the following line in /protected/views/layout/main.php before </head> tag:

<?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>

It will load jQuery automatically. Remember, if the YII_DEBUG flag is on it will load non-minified version, when deactivated (on production) it will load minified version. Hope this will fix your problem.

like image 160
Skatox Avatar answered Oct 13 '22 23:10

Skatox