Where to put javascript file?

I have a single javascript file, which is an jquery plugin, and I'd like to know, where to put this file? Do I have to create an extension?

Hi,

you can put this file in jscripts directory in webroot.

Don't forget to set your client script on your config:



...


'clientScript' => array(


	'coreScriptUrl' => 'path/to/js/lib/dir',


	'enableJavaScript' => true,


),


...


Quote

Don't forget to set your client script on your config:


...


'clientScript' => array(


	'coreScriptUrl' => 'path/to/js/lib/dir',


	'enableJavaScript' => true,


),


...


If I do this:

  'clientScript' => array(

    'coreScriptUrl' => '/scripts',

    'enableJavaScript' => true

  ),

I get an error:

"Property "CWebApplication.clientScript" is read only."

what went wrong?

Where you put this code?

Quote

Where you put this code?

in /protected/config/main.php right between "components" and "params"

You have to put this code in components array



'components'=>array(


   'clientScript' => array(


      'coreScriptUrl' => 'path/to/js/lib/dir',


      'enableJavaScript' => true,


   ),


),


I don't think, he wants to change the location of core scripts. What he wants is to add his own js script. I would suggest to put it anywhere and publish it like described here:

http://www.yiiframew…n.create#widget

To add own script can use registerScriptFile() from CClientScript.

Why can't you just put it anywhere (e.g. <app>/js ) and edit the layout (protected/views/layouts/main.php) to refer to that file? Is there a reason why this is the "wrong" way to do it?

Daniel.

Yes, that's the easiest way if a js is used site-wide.

If a js file is only used by one page or two, you may use registerScriptFile in your action view.

Thanks. Yes, the js I have is used site-wide.