我正在使用CakePHP 3.2
我想在查询WHERE IN ()
代码为
$filter_p_t = $this->request->query('p_t');
$pros10 = $this->Products->find()
->where([
'SellerProducts.stock >' => 0,
'SellerProducts.status' => 1,
'Products.p_status' => 1,
])
->contain([
'SellerProducts',
'ProductTypes.Subcategories.Categories',
]);
此处$filter_p_t
是来自带参数
/products/display/1?p_t[]=1&p_t[]=86
我想在$filter_p_t
条件中添加where
以查找所有IN(1,86)
如何将Cake数组用于CakePHP 3中的WHERE IN条件?
答案 0 :(得分:8)
您可以在列之后直接使用IN
关键字。这假设$filter_p_t
是一个类似array(1, 86)
的数组。
->where(['id IN' => $filter_p_t]);
http://book.cakephp.org/3.0/en/orm/query-builder.html#automatically-creating-in-clauses