在CakePHP中的WHERE IN中使用数组

Anu*_*TBE 4 cakephp where-in cakephp-3.2

我正在开发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',
 ]);
Run Code Online (Sandbox Code Playgroud)

$filter_p_t是来自带参数的url的数组

/products/display/1?p_t[]=1&p_t[]=86
Run Code Online (Sandbox Code Playgroud)

我想包括$filter_p_twhere条件中找到所有IN(1,86)

如何在CakePHP 3中使用php数组到WHERE IN条件?

bil*_*ill 9

您可以IN在列之后直接使用关键字.这是假设这$filter_p_t是一个数组array(1, 86).

->where(['id IN' => $filter_p_t]);
Run Code Online (Sandbox Code Playgroud)

http://book.cakephp.org/3.0/en/orm/query-builder.html#automatically-creating-in-clauses