2

I'm using Yii Framework v1.1.10r3566. I'm noticing in Firebug that the generated code is producing an error. It says "jQuery is not defined" and the line has a function "jQuery(function($)". It is occurring on multiple pages and I believe that it is preventing my zii widgets from operating properly (CJuiDatePicker is not working when previously it had worked). I am not writing any routines using jQuery nor am I including any other javascript library. The generated code on one of the pages that is generating the error is:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="language" content="en" />
<!-- blueprint CSS framework -->
<link rel="stylesheet" type="text/css" href="/myapp/css/screen.css" media="screen, projection" />
<link rel="stylesheet" type="text/css" href="/myapp/css/print.css" media="print" />
<!--[if lt IE 8]>
<link rel="stylesheet" type="text/css" href="/myapp/css/ie.css" media="screen, projection" />
<![endif]-->
<link rel="stylesheet" type="text/css" href="/myapp/css/main.css" />
<link rel="stylesheet" type="text/css" href="/myapp/css/form.css" />
<script type="text/javascript" src="/myapp/assets/ef86d901/jquery.js"></script>
<script type="text/javascript" src="/myapp/assets/ef86d901/jquery.yiiactiveform.js"></script>
<title>myapp - Login</title>
</head>

I'm at wits end and haven't a clue why the generated code is producing this error. Help would be appreciated.

nimble
  • 157
  • 2
  • 7

4 Answers4

3

That error is usually the result of jQuery framework not being installed. It looks like your jquery.js is your jQuery framework since you mention your not using any custom markup yourself.

A quick test is to replace this:

<script type="text/javascript" src="/myapp/assets/ef86d901/jquery.js"></script>

With this:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

Note to replace 1.7.2 with your required jQuery version as explained by using Google's hot-linked API Libraries.

If that solves your issue, then check the path to your local jQuery file or consider using Google's hotlinked API Libaries which has other benefits you can read about.

arttronics
  • 9,957
  • 2
  • 26
  • 62
  • Thank you very much! That seems to fix the problem. Although, I'm not sure what to do about it in Yii. Also, I now receive $("#profile-form").yiiactiveform is not a function. Do I need to replace other libraries as well? – nimble May 29 '12 at 21:39
  • It looks like the **Yii Framework v1.1.10r3566** is not installed either. You will need to check the folder path and redownload it. Also, I am not familiar with that script but perhaps it's missing and should be placed above the **Yii** form you are using. Since this problem was fixed, please accept my answer. Thanks! – arttronics May 29 '12 at 21:50
2

You should include jquery in all controller/action, to do that, insert this code to Controller.php (most parent of all controller in application)

public function beforeAction($action)
   {

      $cs = Yii::app()->clientScript;
      $cs->registerCoreScript('jquery');

   }
kamankily
  • 91
  • 4
1

I had the same problem, then I looked into the "View Source", there, the jquery was loaded from assets and from the "js" directory. So I removed the registerScriptFile('js/jquery'); . Then it was working fine as it loaded jquery only from assets.

Pranav Singh
  • 17,079
  • 30
  • 77
  • 104
Vijay Anand
  • 93
  • 1
  • 8
0

I just had a similar problem, after I'd set components -> assetManager -> linkAssets to true to ensure the "latest" version of assets were being used. I then forgot, and wiped my assets folder, which removed all the original assets!

Handily I was able to revert the originals (version control ftw) and all was restored. Might be useful to others in a similar predicament.

Hippyjim
  • 2,520
  • 6
  • 38
  • 54