can someone provide a simple example of how to use the clientScript class please.
I'd like to have the javascript inserted just before the end body tag and also would like to register specific files for each controller…as opposed to every page loading every file… sure this is possible but can't quite see how to do it.
My problem is that i would normally have a bunch of css and js files included as default. That is i will have them included in my layout file.
However in one view i might want to include some js file specific to that page. Currently i solve this by using CHtml and have them included in my body.
But i would rather want them included in my <head> part just like when you include them with ClientScript. However if i register a css or js in a view it will end up being included above the css and js in my layout file.
So if i for example have mootools included in my layout and have datepicker written in mootools that i would like to use in one of my views it would be included on top of the mootools inclusion and i will end up with JS errors because of that.
My explanation might be a bit confusing, if you like i can give you a html example or do you get my point?
I guess the easiest way of solving this type of problem would probably be to add the option to specify the index key of the file i include. But maybe there is a option already? And i just haven’t stumbled upon it yet?
There's a trick here: if you use registerScriptFile() to insert a script in the head section, the script will be inserted right before the <title> tag. So you can move around your other scripts in the layout so that the inserted script appears in the expected order.
Im haveing the same problem, and moving around myscripts in the layout doesnt help if I use CClientScript::registerScriptFile(). The only way i get it to work its using rather <script src=""> or CHtml::scriptFile(); which I dont really like if im supposed to use CClientScript::registerScriptFile() which would be the "good way".
Is there any other option or is this the only way around?