Jquery In Yii

Hey

I have a Package:




         'des'=>array(

                    'baseUrl'=> 'myassets/des/',

                    'css'    => array( 'css/des.css'),

                    'js'     => array( 'js/des.js'),

                    ),  



and I registered the package of the top of the view:




<?php Yii::app()->clientScript->registerPackage('des'); ?>



I have some functions in the .js file and everything worked. But now i wanted to implement some things like:




$(document).ready(function(){

    ...

});

but i get the error (console): "Uncaught ReferenceError: $ is not defined"

How can I implement things like that? Just with registerscript? I cannot use it in a external file?

Thx for help!

Franker

Your js files are loaded and executed by the browser before jQuery or you haven’t registered the jQuery core script at all.

If it’s about the order and you can’t change that maybe add some kind of init function and call it from a single ‘registerScript’ call, like:




Yii::app()->clientScript->registerScript(__CLASS__.'#init', 'someInitFunction();', CClientScript::POS_READY);






'des'=>array(

    'baseUrl' => 'myassets/des/',

    'css'  => array( 'css/des.css'),

    'js'   => array( 'js/des.js'),

    'depends'  => array('jquery') // <- jQuery  will be downlodaded before your script

),



Hey… thanks. It works!