$this->_product->collCount()

bug问题 · fecshoper · 于 6年前 发布 · 2018 次阅读

这样查询不行嘛 $filter['where'] = ['in', 'category', $category_id]; 总是报错,不是array

共收到 7 条回复
Fecmall#16年前 0 个赞

$filter['where'] = ['in', 'category', $category_id];

这个代码是你自己写的,还是fecshop源码这样写的?

$category_id必须是数组才行,Yii2没有用过?基本语法!

如果直接查询单个分类:

$filter['where'] = ['category' => $category_id]; 
fecshoper#26年前 0 个赞

@Terry #1楼 $category_id就是数组

Fecmall#36年前 0 个赞

函数有注释仔细看

/*
     * @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();
    }
Fecmall#46年前 0 个赞

直接告诉你把

$filter['where'][] = ['in', 'category', $category_id];

fecshoper#56年前 0 个赞

@Terry #4楼 哦哦

fecshoper#66年前 0 个赞

@Terry #4楼 laravel用多了

Fecmall#76年前 0 个赞

@fecshoper [#6楼](#comment6) yii2也是这样的,是没有问题的,是Fecshop进行封装了

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics