gpt4 book ai didi

php - Cgridview 'filter' 属性出错,错误代码::没有方法 'querystring'

转载 作者:行者123 更新时间:2023-12-01 03:41:34 28 4
gpt4 key购买 nike

我在使用 CGridview 中的筛选功能时遇到问题。过滤盒根本不起作用。当我输入内容并按回车键时,没有任何反应。

这里是查看代码selectproducts.php::

<div id="shortcodes" class="page">
<div class="container">

<!-- Title Page -->
<div class="row">
<div class="span12">
<div class="title-page">
<h2 class="title">Available Products</h2>

</div>
</div>
</div>
<!-- End Title Page -->



<!-- Start Product Section -->
<div class="row">


<?php


$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'products-grid',
'dataProvider' => $dataProvider,
'filter' => $dataProvider->model,
'ajaxUpdate' => TRUE,
'pager' => array(
'header' => '',
'cssFile' => false,
'maxButtonCount' => 25,
'selectedPageCssClass' => 'active',
'hiddenPageCssClass' => 'disabled',
'firstPageCssClass' => 'previous',
'lastPageCssClass' => 'next',
'firstPageLabel' => '<<',
'lastPageLabel' => '>>',
'prevPageLabel' => '<',
'nextPageLabel' => '>',
),
'columns' => array(
'id',
array(
'name' => 'name',

),
'category',
'brand',
'weight_unit',
'price_unit',
'flavors',
array(
'name' => 'providers',
'value' => function($data) {
return '<div class="provider-label label label-info"><a href="http://www.'.$data->providers. '">'. $data->providers .'</a></div>';
},
'type' => 'raw',
),
),
));
?>

</div>
<!-- End Product Section -->


</div>

这是 ProductsController 中渲染此 View 的相关操作。 View 中的 $dataprovider 变量是一个 CActiveDataProvider 对象,它保存条件查询的结果。

public function actionDropdown() {

if (isset($_GET["Dropdown"])) {
$dropdownData = $_GET["Dropdown"];
$this->category = $dropdownData["category"];
$this->price = $dropdownData["price"];
}
// separate the price text into min and max value
$priceText = explode(" - ", $this->price);



$criteria = new CDbCriteria;
$criteria->compare('category', $this->category, true);

$criteria->addBetweenCondition('price', substr($priceText[0], 1), substr($priceText[1], 1), 'AND');

$dataProvider = new CActiveDataProvider('Products', array(
'criteria' => $criteria,
'pagination' => array(
'pageSize' => 20,
),
'sort' => array(
'defaultOrder' => 'price_unit, name',
),
));


$this->render('selectproducts', array(
'dataProvider' => $dataProvider,
'criteria' => $criteria,
));
}

这是 Products() 模型 search() 函数::

public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.

$criteria=new CDbCriteria;

$criteria->compare('id',$this->id);
$criteria->compare('name',$this->name,true);
$criteria->compare('category',$this->category,true);
$criteria->compare('brand',$this->brand,true);
$criteria->compare('weight',$this->weight,true);
$criteria->compare('weight_unit',$this->weight_unit,true);
$criteria->compare('price',$this->price,true);
$criteria->compare('price_unit',$this->price_unit,true);
$criteria->compare('flavors',$this->flavors,true);
$criteria->compare('providers',$this->providers,true);

return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}

现在,当我在过滤器框中按回车键时,我收到此错误,该错误已记录在 firebug 中

TypeError: $.param.querystring is not a function
[Break On This Error]

options.url = $.param.querystring(options.url, options.data);

In file jquery.yiigridview.js

有谁知道是什么原因导致此错误。我只是不明白是什么原因造成的。而且我也不知道应该在 jquery.yiigridview.js 中进行哪些修改来修复此错误。

提前致谢。麦克斯

编辑

根据下面tinyByte的建议。我尝试将 CActiveDataProvider 逻辑移至模型,以便我可以在 GridView 'dataProvider' 属性中使用 $model->search(),但它仍然没有帮助解决相同的错误。

这是代码

Controller :::

public function actionDropdown() {

$dataProvider = new Products;

if (isset($_GET["Dropdown"])) {
$dropdownData = $_GET["Dropdown"];
$this->category = $dropdownData["category"];
$this->price = $dropdownData["price"];
}


$this->render('selectproducts', array(
'dataProvider' => $dataProvider,
'category' => $this->category,
'price' => $this->price,
//'num' => $this->numResults,
));
}

这是模型::

public function searchDropdown($category, $price) {

$this->priceText = explode(" - ", $price);

$this->criteria = new CDbCriteria;
$this->criteria->compare('category', $category, true);

$this->criteria->addBetweenCondition('price', substr($this->priceText[0], 1), substr($this->priceText[1], 1), 'AND');

return new CActiveDataProvider('Products', array(
'criteria' => $this->criteria,
'pagination' => array(
'pageSize' => 25,
),
'sort' => array(
'defaultOrder' => 'price_unit, name',
),
));



}

这是 View ::

<div id="shortcodes" class="page">
<div class="container">

<!-- Title Page -->
<div class="row">
<div class="span12">
<div class="title-page">
<h2 class="title">Available Products</h2>

</div>
</div>
</div>
<!-- End Title Page -->



<!-- Start Product Section -->
<div class="row">


<?php


$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'products-grid',
'dataProvider' => $dataProvider->searchDropdown($category, $price),
'filter' => $dataProvider,
'ajaxUpdate' => TRUE,
'pager' => array(
'header' => '',
'cssFile' => false,
'maxButtonCount' => 25,
'selectedPageCssClass' => 'active',
'hiddenPageCssClass' => 'disabled',
'firstPageCssClass' => 'previous',
'lastPageCssClass' => 'next',
'firstPageLabel' => '<<',
'lastPageLabel' => '>>',
'prevPageLabel' => '<',
'nextPageLabel' => '>',
),
'columns' => array(
array(
'name' => 'id',
'type' => 'raw',
),
array(
'name' => 'name',


),
'category',
'brand',
'weight_unit',
'price_unit',
'flavors',
array(
'name' => 'providers',
'value' => function($data) {
return '<div class="provider-label label label-info"><a href="http://www.'.$data->providers. '">'. $data->providers .'</a></div>';
},
'type' => 'raw',
),
),
));
?>

</div>
<!-- End Product Section -->


</div>

它仍然不起作用。即,当我在过滤框中输入内容并按 Enter 键时,什么也没有发生。出现同样的错误::

在 Firebug 中

TypeError: $.param.querystring is not a function
[Break On This Error]

options.url = $.param.querystring(options.url, options.data);

In file jquery.yiigridview.js

在 Chrome 中,我收到了一条更具描述性的错误消息。

    Uncaught TypeError: Object function (e,n){var r,i=[],o=function(e,t)

{t=x.isFunction(t)?t():null==t?"":t,i[i.length]=encodeURIComponent(e)+"="+encodeURIComponent(t)};if(n===t&&(n=x.ajaxSettings&&

x.ajaxSettings.traditional),x.isArray(e)||e.jquery&&!x.isPlainObject(e))x.each(e,function(){o(this.name,this.value)});
else for(r in e)gn(r,e[r],n,o);return i.join("&").replace(cn,"+")}

has no method 'querystring'

jquery.yiigridview.js:310

我就是不知道该怎么办。

编辑

好吧,经过长时间的努力,在 Yii 论坛 http://www.yiiframework.com/forum/index.php/topic/47904-error-with-cgridview-filter-property-error-code-has-no-method-querystring/page_view_findpost_p_224169 的一位论坛伙伴的帮助下,我设法摆脱了这个错误。 。

这是我添加的内容。

 <script src="<?php echo Yii::app()->assetManager->baseUrl; ?>/28e7347b/jquery.ba-bbq.js"></script>
<script src="<?php echo Yii::app()->assetManager->baseUrl; ?>/28e7347b/jquery.jquery.ajaxqueue.js"></script>
<script src="<?php echo Yii::app()->assetManager->baseUrl; ?>/28e7347b/jquery.autocomplete.js"></script>
<script src="<?php echo Yii::app()->assetManager->baseUrl; ?>/28e7347b/jquery.bgiframe.js"></script>
<script src="<?php echo Yii::app()->assetManager->baseUrl; ?>/28e7347b/jquery.maskedinput.js"></script>
<script src="<?php echo Yii::app()->assetManager->baseUrl; ?>/28e7347b/jquery.metadata.js"></script>
<script src="<?php echo Yii::app()->assetManager->baseUrl; ?>/28e7347b/jquery.treeview.js"></script>
<script src="<?php echo Yii::app()->assetManager->baseUrl; ?>/28e7347b/jquery.treeview.async.js"></script>
<script src="<?php echo Yii::app()->assetManager->baseUrl; ?>/28e7347b/jquery.treeview.edit.js"></script>
<script src="<?php echo Yii::app()->assetManager->baseUrl; ?>/28e7347b/jquery.yii.js"></script>
<script src="<?php echo Yii::app()->assetManager->baseUrl; ?>/28e7347b/jquery.yiiactiveform.js"></script>
<script src="<?php echo Yii::app()->assetManager->baseUrl; ?>/28e7347b/jquery.yiitab.js"></script>
<script src="<?php echo Yii::app()->assetManager->baseUrl; ?>/28e7347b/punycode.js"></script>

错误消失,但过滤器仍然无法工作。 ajax 加载图标显示不到一秒,然后什么也没有发生。我还看到数组中传递了正确的搜索参数。

这是我看到传递的数组

Dropdown[category]  Chant Books
Dropdown[price] $340 - $476
Products[brand]
Products[category]
Products[flavors]
Products[name] Owl Chant Scroll
Products[price_unit]
Products[providers]
Products[weight_unit]
Products_page 1
ajax products-grid
yt0

最佳答案

根据我的经验,这个错误的原因是jQuery冲突:有一个是你加载的,另一个是cgridview加载的。解决方案是删除您的 jquery,或者如果您必须拥有它 - 删除 Yii 的 jquery:

$cs=Yii::app()->clientScript;
$cs->scriptMap=array(
'jquery.js'=>false,
);

关于php - Cgridview 'filter' 属性出错,错误代码::没有方法 'querystring',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19330816/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com