这样查询不行嘛 $filter['where'] = ['in', 'category', $category_id]; 总是报错,不是array
$filter['where'] = ['in', 'category', $category_id];
这个代码是你自己写的,还是fecshop源码这样写的?
$category_id必须是数组才行,Yii2没有用过?基本语法!
$category_id
如果直接查询单个分类:
$filter['where'] = ['category' => $category_id];
@Terry #1楼 $category_id就是数组
函数有注释仔细看
/* * @property $filter | Array , example filter: * [ * 'numPerPage' => 20, * 'pageNum' => 1, * 'orderBy' => ['_id' => SORT_DESC, 'sku' => SORT_ASC ], * 'where' => [ ['>','price',1], ['<=','price',10] * ['sku' => 'uk10001'], * ], * 'asArray' => true, * ] * 得到总数。 */ public function collCount($filter = '') { $query = $this->_productModel->find(); $query = Yii::$service->helper->ar->getCollByFilter($query, $filter); return $query->count(); }
直接告诉你把
$filter['where'][] = ['in', 'category', $category_id];
@Terry #4楼 哦哦
@Terry #4楼 laravel用多了
@fecshoper [#6楼](#comment6) yii2也是这样的,是没有问题的,是Fecshop进行封装了