Incorporating custom jquery script inside of YII framwork

Hello Guys,

Can some one tell me how to incorporate a custom jquery script inside of yii?

Here is the one that I want to implement (2234

vscroller.zip
attached zip file to this ticket.)

I am a newbie and I don’t understand how to include custom scripts inside of yii…

If you know of a jquery scroller with XML file reading capable abilities that will install easily in yii, please let me know…

Please advise.

Thanks, Dan

Just create a new javascript file and include it in your controller or in the <head> of the view layout

Hi dk4210,

the exact solution depends on whether you need JS file included on all (or mostly all) pages of site or on just several ones:

  • if former - include JS file in layout file, but notice that Yii includes bundled scripts (like jQuery) right before <title>-tag, so you better place you <script>-tag(s) after <title>-tag.
  • if latter - then you might use CClientScript::registerScriptFile in you controller or view like this:



Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/yourFile.js');



Ok That’s it?

Easy enough… I thought there was a specific structure with this framework…

afaik Yii does a replace on </head> and replaces it with [js files]</head> so it has nothing to do with title tag

CClientScript::renderHead:




....

if($html!=='')

    {

        $count=0;

        $output=preg_replace('/(<title\b[^>]*>|<\\/head\s*>)/is','<###head###>$1',$output,1,$count);

        if($count)

            $output=str_replace('<###head###>',$html,$output);

        else

            $output=$html.$output;

    }

....



So you can see that JS codes are being included before <title>-tag, but if no <title>-tag presented - then before </head>-tag.

Ok we were both right ;)