2

I am using yii framework with Boostrap and Booster. On my web page i need to use jQuery version 1.9.1. When i include it eg

$cs->registerScriptFile($baseUrl . '/js/jquery-1.11.2.min.js')

i start getting all kinds of Jquery errors eg jQuery(...).rating is not a function ect..

I need to include the jquery1.11.2 in order to have all functionalities working. What should i do , i tried disabling js loading in booster , i tried updating bootstrap and booster i tried placing the jquery file in different sections of my page but all my attempts have been futile. Please help me identifie the problem

Gunnit
  • 1,064
  • 5
  • 22
  • 45

2 Answers2

2

By default, Yii has own JQuery library. In bootstrap, trying to load Yii Core JS files. If you load your JQuery then it will conflict and will gives you errors. There are 2 ways to overcome.

  1. Update Yii core jquery files with your latest one. Simple but not advisable to change Core files.
  2. You can ask Yii to take your Jquery file instead of Core one in main.php >> components section you need to add as below

    'clientScript'=>array(
        'packages'=>array(
            'jquery'=>array(
                'baseUrl'=> 'Yii::app()->baseUrl',
                'js'=>array('1.7.2/jquery.min.js'),
                )
             ),
     ),
    

Hope this helps !!

Regards

Sanjay Mohnani
  • 990
  • 7
  • 18
  • Thanks buddy, i tried option 2 but i get "Call to a member function getBaseUrl() on a non-object" when i remove that line nothing works. Plz if u have another min help me out . Thanks – Gunnit May 13 '15 at 07:55
  • Try with new edit i did. Added quote around. Also try without quote. – Sanjay Mohnani May 13 '15 at 10:36
  • 'baseUrl'=> 'Yii::app()->baseUrl' INSTEAD OF 'baseUrl'=> Yii::app()->baseUrl – Sanjay Mohnani May 13 '15 at 13:15
  • thanks buddy your answer is correct , i just added the absolute path like this 'baseUrl' => 'http://localhost:8080/traveltour/', – Gunnit May 13 '15 at 15:30
0

Best way to use jQuery 1.11.2 with bootstrap 3 and yii you should just take care of position of load jQuery yii default jQuery must be loaded after load custom js see below example piece of code

Yii::app()->clientScript->registerScriptFile(Yii::app()->params['designFrontEnd']. 'js/jquery-1.11.2.min.js');

Yii::app()->clientScript->coreScriptPosition=CClientScript::POS_END; Yii::app()->clientScript->registerCoreScript('jquery'); Yii::app()->clientScript->registerCoreScript('jquery.ui');

Community
  • 1
  • 1
D M Patel
  • 86
  • 4