2

I am looking for some possiblility to pass a paramter in contain's function

$query = $products->find()->contain([
    'Categories' => function ($q) {
       return $q->where(['Categories.category_id' => $categoryId]);
    }
]);

in this case I want to pass $categoryId as argument.

sradha
  • 2,216
  • 1
  • 28
  • 48
user3733648
  • 1,323
  • 1
  • 10
  • 25
  • 2
    http://stackoverflow.com/questions/16959576/reference-what-is-variable-scope-which-variables-are-accessible-from-where-and – ndm Aug 18 '16 at 11:22
  • 4
    ```function ($q) use ($categoryId) { ...``` – Salines Aug 18 '16 at 13:18
  • http://book.cakephp.org/3.0/en/orm/retrieving-data-and-resultsets.html#filtering-by-associated-data check this , function ($q) use ($categoryId) { return $q->where(['Categories.category_id' => $categoryId] – sradha Aug 31 '16 at 07:06

0 Answers0