Adding Jquery from the Yii Framework to layout head

This is probably an easy one, but I cannot find the answer in the docs or searching the forum.

I’ve been including my own copy of JQuery 1.4.2 into my head but this breaks some of the yii jQuery functionality. Instead I just want to include the included jQuery version using a Yii function. I’m assuming it’s part of CHtml but cannot find how to do it?

Is that what you mean?


Yii::app()->clientScript->registerCoreScript('jquery')

Also check out the scriptMap feature, described on this page:

http://www.yiiframework.com/doc/guide/topics.performance

Sorry, reading it back it does sound confusing…

I just want to include Yii’s jQuery version in all my layout files instead of hard coding my own as the latest version seems to break a few things.

Not sure where Yii::app()->clientScript->registerCoreScript(‘jquery’) is meant to be placed?

I did read that article but it doesn’t make sense to me.

Putting it somewhere on top of your layout file should be fine:


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



On the other hand, Yiis jquery gets included automatically when you use any of Yii’s widgets that rely on jquery.

Excellent, just tried that and it works. Many thanks.