gpt4 book ai didi

php - CGridview 有条件显示相关模型数据

转载 作者:行者123 更新时间:2023-11-30 00:25:49 28 4
gpt4 key购买 nike

我正在尝试按category_id过滤gridview中的产品记录

我有三张 table

ProductMst(product_id,name)

CategoryMst(category_id,category_nme)

PromotedUserProduct(category_id,product_id) ====> junction table

ProductMst 模型规则如下

   public function relations()
{

return array(
'categoryMsts' => array(self::MANY_MANY, 'CategoryMst', 'promoted_user_product(user_product_id, category_id)'),

);
}

我的 Controller 代码是这样的

         $criteria=new CDbCriteria();
$categoryCondition=array();
if(isset($_GET['category_id']) && $_GET['category_id']!==""){
$categoryCondition=array('select'=>false,
'condition'=>'categoryMsts.category_id=1',
'joinType'=>'INNER JOIN ');
}

$criteria->with=array(
'categoryMsts'=>$categoryCondition);



$dataProvider=new CActiveDataProvider('UserProductDtl',array(
'pagination'=>array(
'pageSize'=>$pagesize,
),
'criteria'=>$criteria,
));
$this->render('index',
array('dataProvider'=>$dataProvider));

我无法过滤记录,有人可以帮我吗?

最佳答案

改变这个

$categoryCondition=array(
'select'=>false,
'condition'=>'category_id=:category_id',
'params'=>['category_id'=>$_GET['category_id'],
'joinType'=>'INNER JOIN '
);

关于php - CGridview 有条件显示相关模型数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22896469/

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