Php Cgridview'错误;过滤器';属性,错误代码::没有方法';查询字符串';
我对CGridview中的过滤器功能有问题。过滤盒根本不工作。当我键入内容并按enter键时,不会发生任何事情 以下是查看代码selectproducts.php::Php Cgridview'错误;过滤器';属性,错误代码::没有方法';查询字符串';,php,jquery,yii,Php,Jquery,Yii,我对CGridview中的过滤器功能有问题。过滤盒根本不工作。当我键入内容并按enter键时,不会发生任何事情 以下是查看代码selectproducts.php:: <div id="shortcodes" class="page"> <div class="container"> <!-- Title Page --> <div class="row"> <div class="span12">
<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>
下面是Products()model 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,
));
}
现在,当我点击过滤器框中的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
有人知道是什么导致了这个错误吗。我只是不知道是什么原因造成的。我也不知道在jquery.yiigridview.js中应该做什么修改来修复这个错误
提前谢谢。
马克斯
编辑
根据下面tinyByte的建议。我试图将CActiveDataProvider逻辑移到模型中,这样我就可以在GridView的“dataProvider”属性中使用$model->search(),但仍然无法解决相同的错误
这是密码
控制器:::
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',
),
));
}
以下是视图:
<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>
在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论坛的一位论坛伙伴的帮助下,设法摆脱了这个错误
以下是我补充的内容
<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>
filter属性用于验证,您需要为网格的属性“dataprovider”提供搜索功能
$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'products-grid',
'dataProvider' => $model->customeSearch(), // add your method of search here
'filter' => $model, // for validation
...
'columns' => array(
array(
'name' => 'someCol',
'value' => '$data->someCol',
'filter' => CHtml::dropdownList( ... ), // put an input here for your filter
),
),问题终于解决了。事实证明,我需要添加Gridview小部件的ajaxUpdate和ajaxURL属性。并对ajax过滤器执行另一个操作
'ajaxUpdate' => 'products-grid',
'ajaxUrl' => Yii::app()->createUrl('products/UpdateGrid'),
不管怎样,这里是代码,它现在可以工作了
产品控制器中的操作方法::
public function actionDropdown() {
/*
* create the session to store the dropdown variables
*
*
*/
$this->session = new CHttpSession;
$this->session->open();
$dataProvider = new Products;
$products = new Products('search');
$products->unsetAttributes();
if (isset($_GET["Dropdown"])) {
$dropdownData = $_GET["Dropdown"];
$this->category = $dropdownData["category"];
$this->price = $dropdownData["price"];
$this->session["category"] = $this->category;
$this->session["price"] = $this->price;
}
if (isset($_GET["Products"])) {
$products->attributes = $_GET["Products"];
}
$this->render('selectproducts', array(
'dataProvider' => $dataProvider,
'products' => $products,
'category' => $this->category,
'price' => $this->price,
//'num' => $this->numResults,
));
}
public function actionUpdateGrid() {
$products = new Products;
$products->unsetAttributes();
if (isset($_GET["Products"])) {
$products->attributes = $_GET["Products"];
}
$this->renderPartial('_selectproducts', array(
'products' => $products,
'category' => $this->category,
'price' => $this->price,
));
}
产品型号代码::
/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* @return CActiveDataProvider the data provider that can return the models
* based on the search/filter conditions.
*/
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,
));
}
/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return Products the static model class
*/
public static function model($className = __CLASS__) {
return parent::model($className);
}
/*
* Dropdown search
*
*
*/
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',
),
));
}
public function searchGrid() {
$session = new CHttpSession;
$session->open();
$category = $session["category"];
$this->criteria = new CDbCriteria;
$this->priceText = explode(" - ", $session["price"]);
$this->criteria->compare('category', $category, true);
$this->criteria->addBetweenCondition('price', substr($this->priceText[0], 1), substr($this->priceText[1], 1), 'AND');
/*
*
* compare the names to see if the flavor or weight is present
*
*/
$this->criteria->compare('name', $this->flavors, TRUE);
$this->criteria->compare('name', $this->weight, TRUE);
$this->criteria->compare('id', $this->id);
$this->criteria->compare('name', $this->name, true);
$this->criteria->compare('category', $this->category, true);
$this->criteria->compare('brand', $this->brand, true);
$this->criteria->compare('weight', $this->weight, true);
$this->criteria->compare('weight_unit', $this->weight_unit, true);
$this->criteria->compare('price', $this->price, true);
$this->criteria->compare('price_unit', $this->price_unit, true);
$this->criteria->compare('flavors', $this->flavors, true);
$this->criteria->compare('providers', $this->providers, true);
return new CActiveDataProvider($this, array(
'criteria' => $this->criteria,
'pagination' => array(
'pageSize' => 25,
),
'sort' => array(
'defaultOrder' => 'price_unit, name',
),
));
}
意见如下:
视图名称::-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->searchDropdown($category, $price),
'filter' => $products,
'ajaxUpdate' => 'products-grid',
'ajaxUrl' => Yii::app()->createUrl('products/UpdateGrid'),
'pager' => array(
'header' => '',
'cssFile' => false,
'maxButtonCount' => 25,
'selectedPageCssClass' => 'active',
'hiddenPageCssClass' => 'disabled',
'firstPageCssClass' => 'previous',
'lastPageCssClass' => 'next',
'firstPageLabel' => '<<',
'lastPageLabel' => '>>',
'prevPageLabel' => '<',
'nextPageLabel' => '>',
),
'columns' => array(
array(
'name' => 'name',
'value' => function($data) {
return '<div class="custom-badge">' . $data->name . '</div>';
},
'type' => 'raw',
),
array(
'name' => 'category',
'value' => function($data) {
return '<div class="grid-glow">' . $data->category . '</div>';
},
'type' => 'raw',
),
array(
'name' => 'brand',
'value' => function($data) {
return '<div class="grid-glow">' . $data->brand . '</div>';
},
'type' => 'raw',
),
array(
'name' => 'weight_unit',
'value' => function($data) {
return '<div class="grid-glow">' . $data->weight_unit . '</div>';
},
'type' => 'raw',
),
array(
'name' => 'price_unit',
'value' => function($data) {
return '<div class="grid-price-glow">' . $data->price_unit . '</div>';
},
'type' => 'raw',
),
array(
'name' => 'flavors',
'value' => function($data) {
return '<div class="grid-glow">' . $data->flavors . '</div>';
},
'type' => 'raw',
),
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>
<?php
$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'products-grid',
'dataProvider' => $products->searchGrid($category, $price),
'filter' => $products,
'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' => 'name',
'value' => function($data) {
return '<div class="custom-badge">' . $data->name . '</div>';
},
'type' => 'raw',
),
array(
'name' => 'category',
'value' => function($data) {
return '<div class="grid-glow">' . $data->category . '</div>';
},
'type' => 'raw',
),
array(
'name' => 'brand',
'value' => function($data) {
return '<div class="grid-glow">' . $data->brand . '</div>';
},
'type' => 'raw',
),
array(
'name' => 'weight_unit',
'value' => function($data) {
return '<div class="grid-glow">' . $data->weight_unit . '</div>';
},
'type' => 'raw',
),
array(
'name' => 'price_unit',
'value' => function($data) {
return '<div class="grid-price-glow">' . $data->price_unit . '</div>';
},
'type' => 'raw',
),
array(
'name' => 'flavors',
'value' => function($data) {
return '<div class="grid-glow">' . $data->flavors . '</div>';
},
'type' => 'raw',
),
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',
),
),
));
?>
可用产品
试试这个代码
$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'products-grid',
'dataProvider' => $model->customeSearch(), // add your method of search here
'filter' => $model, // for validation
'ajaxUrl'=> Yii::app()->request->getUrl(),
...
根据我的经验,这个错误的原因是jQuery冲突:有一个是您加载的,另一个是由cgridview加载的。
解决方案是删除jquery,或者如果必须删除jquery,则删除Yii的jquery:
$cs=Yii::app()->clientScript;
$cs->scriptMap=array(
'jquery.js'=>false,
);
刷新yii js文件。在配置中:
'components'=>array(
'clientScript' => array(
'packages' => array(
'jquery' => array(
'baseUrl' => 'js',
'js' => array(
'jquery-1.10.2.js',
'jquery-migrate-1.2.1.min.js',
)
),
),
),
)
TypeError:$.param.querystring不是函数
[在此错误上中断]
options.url=$.param.querystring(options.url,options.data)代码>
在文件jquery.yiigridview.js
我也遇到了上面提到的同样的问题,很容易解决。当包含的jQuery与jQuery.yiigridview.js
添加的默认js冲突时,通常会发生这种情况
试着简单地删除您包含的min.js,它会工作得非常好。您好,谢谢您的帮助。我试图应用你的建议,但仍然给我同样的错误。查看上面的编辑。我认为这与javascript文件jquery.yiigridview.js有关。但是我不知道我应该对那个文件做什么修改来修复它,所以有人知道这个问题的修复方法吗。我真的被这件事缠住了。谢谢。我还添加了$cs->coreScriptPosition=CClientScript::POS\u END代码>之后,因为在加载插件后加载jQuery导致脚本中出现错误,所以jQuery未定义。
$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'products-grid',
'dataProvider' => $model->customeSearch(), // add your method of search here
'filter' => $model, // for validation
'ajaxUrl'=> Yii::app()->request->getUrl(),
...
$cs=Yii::app()->clientScript;
$cs->scriptMap=array(
'jquery.js'=>false,
);
'components'=>array(
'clientScript' => array(
'packages' => array(
'jquery' => array(
'baseUrl' => 'js',
'js' => array(
'jquery-1.10.2.js',
'jquery-migrate-1.2.1.min.js',
)
),
),
),