Yii不是自动包含jQuery的 [英] Yii is not auto including jquery

查看:74
本文介绍了Yii不是自动包含jQuery的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Yii& jQuery:

I have a strange problem with Yii & Jquery:

当我打开在localhost Yii上使用ajax/jquery的页面时,会自动向该页面的资产添加资产包含调用:

When I open a page which uses ajax/jquery on localhost Yii does automatically add asset include calls to the of the page:

<link rel="stylesheet" type="text/css" href="/PATH/assets/f72b359d/style.css" />
<script type="text/javascript" src="/PATH/assets/2e442e1a/jquery.js"></script>
<script type="text/javascript" src="/PATH/assets/2e442e1a/jquery.cookie.js"></script>

但是,当我在服务器上运行相同的代码时,Yii却没有执行此操作,因此没有可用的Jquery.

However when I run same code on the server Yii does not do it hense no Jquery available.

如果有人能找到解决问题的方法,我将不胜感激.

I'd appreciate if someone could direct to a way to solve it.

推荐答案

似乎您没有以正确的方式注册jQuery.您必须在 </head> 标记之前的/protected/views/layout/main.php中添加以下行:

It seems like you're not registering jQuery in the correct way. You must add the following line in /protected/views/layout/main.php before </head> tag:

<?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>

它将自动加载jQuery.请记住,如果 YII_DEBUG 标志处于启用状态,它将加载非缩小版本,停用(在生产环境中)时,它将加载缩小的版本.希望这能解决您的问题.

It will load jQuery automatically. Remember, if the YII_DEBUG flag is on it will load non-minified version, when deactivated (on production) it will load minified version. Hope this will fix your problem.

这篇关于Yii不是自动包含jQuery的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆