Alexei Tenitski
Alexei Tenitski

Reputation: 9360

Yii is not auto including jquery

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.

Upvotes: 8

Views: 13980

Answers (2)

Thomas Mery
Thomas Mery

Reputation: 120

If all is working on your local machine it might be a permission problems

Have you checked that /assets is writable on your server ?

Yii publishes the assets it needs at runtime in this directory

Upvotes: 1

Skatox
Skatox

Reputation: 4284

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.

Upvotes: 20

Related Questions