【问题标题】:Deprecated JQuery Methods in YII app (yii 1.1.4)YII 应用程序中弃用的 JQuery 方法 (yii 1.1.4)
【发布时间】:2014-07-13 14:48:32
【问题描述】:
我想在我的 yii 应用程序中更改 jquery,使用 jquery 1.9 而不是使用 yii 中的 jquery。
但我发现 jquery-ba-bbq.js 和 main.js 中有些方法被弃用了,例如 $.browser() 和 $.live()
我的问题:
1. 如何删除这两个 js,因为它们是由 yii 应用程序自动加载的。我应该使用哪个配置文件。
2. 我应该改用modernzr lib吗?
提前谢谢
【问题讨论】:
标签:
javascript
php
jquery
yii
【解决方案1】:
'clientScript'=>array(
'packages'=>array(
'jquery'=>array(
'baseUrl'=> 'siteasset/jquery' ,
'js'=>array('jquery-1.10.2.min.js','jquery.browser.js'),
// you can also add css files
'css'=>array('css file path')
)
),
),
把它放在你的main.php文件中config文件夹下...在main.php下components..并在controller.php中注册你的包在components文件夹下..你的控制器.php应该是这样的
<?php
class Controller extends CController
{
/**
* @var string the default layout for the controller view. Defaults to '//layouts/column1',
* meaning using a single column layout. See 'protected/views/layouts/column1.php'.
*/
public $layout='//layouts/content';
/**
* @var array context menu items. This property will be assigned to {@link CMenu::items}.
*/
public $menu=array();
/**
* @var array the breadcrumbs of the current page. The value of this property will
* be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
* for more details on how to specify this property.
*/
public $breadcrumbs=array();
public function beforeAction($action) {
$cs = Yii::app()->clientScript;
$url = Yii::app()->baseUrl;
if(Yii::app()->request->isAjaxRequest)
{
}
else
{
$cs->registerPackage('jquery');
// here you can also register your another css
// and js file .. this code will be
// executed every time before an action
// is called via ajax or in normal way..
//another thing here you can also controll
//in which type of request which scipts
// shiould be generated again..
//here you can see i am not sending
//any js /css files if there is ajax request
}
return parent::beforeAction($action);
}
}
通过这个你可以改变你的 js/css 文件,这些文件来自你的默认 Yii 框架....
我也想包括 jquery1.7 和更高版本...没有 jquery.browser.js 不包括在内,因此您必须单独下载并单独附加。你可以在这里得到它jquery.browser.js
【解决方案2】:
如果您是第一个问题,请在配置文件中使用 clientScript scriptMap 选项:
...
'clientScript' => array(
'scriptMap' => array(
'jquery.min.js' => 'your URL or Google CDN link',
),
),
...
您也可以使用升级后的库来实现 jQuery 兼容性。如果您确实修复了兼容性错误,请在您的更新中发送一些拉取请求,以便主 jQuery 库也可以在以后更新:-)