How to use jquery/javascript in yii?,
How to use my Script in yii?
Why is this any different from using jQuery in any other way?
How to use jquery/javascript in yii?,
How to use my Script in yii?
Why is this any different from using jQuery in any other way?
This is a sample script that I just used in my app development:
using Yii’s registerScript to load our jQuery, which if used normally looks like this:
Now if we use Yii’s Script like this:
You will see that you need to pass 3 things to the Yii::app()->clientScript->registerScript function, firstly a script name, which is not really important; it must just bee unique from any other script name on the same page. LINK
As you stated above you can either register a new script block or you can register a new external script file. You cna also register assets within plugins which will take entire JS folders and combine them into your app.
So there are many ways to use JQuery in Yii.
JQuery comes pre-bundled and activated with JQuery and the JQuery library itself is considered a core script so there is no real need to put your own JQuery in.
You can overwrite the built in JQuery with your own by putting:
Something like that somewhere within either your layout, action or view. I prefer to put this within the layout and manage my own JQuery version personally.
Mainly due to standardisation and interoperability of the framework and its components. Coming pre-bundled with built in hooks for JQuery UI widgets and JQuery elements in general makes the framework much easier to build reusable and clean JS objects for use in your app.
Also I like JQuery so it makes sense for it to come pre-bundled in my opinion. However this is not a call to arms for JQuery being the only JS library/framework out there and you should really consider which is best for you before you choose.