我是yii中的newbei,当一个人点击某个类别时会在gridview中显示该特定类别下的所有产品
视图 产品分类
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'admin-grid',
'dataProvider'=>$model->SelectedCategoryProducts,
'filter'=>$model,
'columns'=>array(
'Name',
'Model',
'Brand',
'Price',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
控制器 产品
public function actionProductcategory($id)
{
$model= Product::model()->SelectedCategoryProducts($id);
var_dump($model);
$this->render('productcategory',array(
'model'=>$model,'id'=>$id,
));
} 模型 产品
public function SelectedCategoryProducts($id)
{
$dataProvider=new CActiveDataProvider('Product', array(
'criteria'=>array(
'select'=>'name,model,price,brand',
'condition'=>'category=:category',
'params'=>array(':category'=>$id),
)));
var_dump($dataProvider);
return $dataProvider;
}
CException
Property "CActiveDataProvider.sellerSelectedCategoryProducts" is not defined.
请帮助!我对此失去了理智......无法在gridview中显示。
答案 0 :(得分:0)
希望这可能会有所帮助
控制器文件
public function actionProductcategory($id)
{
$model=new Product;
$this->render('productcategory',array('model'=>$model,
'id'=>$id));
}
在视图文件中
'dataProvider'=>$model->SelectedCategoryProducts($id),
更新1
'columns'=>array(
'name',
'model',
'brand',
'price',
将它们更改为小写,这是原始列名
答案 1 :(得分:0)
将$ id传递给您的视图文件。
$this->render('productcategory',array('model'=>$model,'id'=>$id));
然后将id传递给ccgridview函数中的模型函数。
'dataProvider'=>$model->SelectedCategoryProducts($id),
答案 2 :(得分:0)
$dataProvider=new CActiveDataProvider('Product', array(
'criteria'=>array(
'select'=>'name,model,price,brand',
'condition'=>'category=:category',
'params'=>array(':category'=>$id),
)));
这可以检索所需的数据....首先检查数据是否完美......是否在第二步之后......