我正在开发一个简单的网上商店,我有一张桌子大小与产品有很多关系。我想找到一定大小的所有产品: / products-by-size / XL我的控制器和操作是:
public function productsBySize($size){
$slug = $this->request->session()->read('Category.slug');
$gender = $this->request->session()->read('Category.gender');
$this->paginate = [
'contain' => ['Categories', 'Taxes', 'Manufactures', 'Promotions', 'ProductImages', 'Sizes'],
'maxLimit' => 9,
'order' => ['price'=>'ASC']
];
$sub = $this->buildTree($this->Categories->find()->toArray());
$categories = $this->treeToHtml($sub);
$products = $this->paginate($this->Products->find()->where([
'Categories.slug'=>$slug,
'gender'=>$gender,
**'Sizes.name'=>$size**
]));
if($slug == 'promotion'){
$products = $this->paginate($this->Products->find()->where([
'promotion_id >'=>0,
'gender'=>$gender,
'Sizes.name'=>$size
]));
}
if($slug == 'all'){
$products = $this->paginate($this->Products->find('all')->where([
'gender'=>$gender,
'Sizes.name'=>$size
]));
}
$sizes = $this->Sizes->find('all');
$this->set(compact('products', 'slug', 'categories', 'sizes'));
$this->render('products', 'Webshop.default', ['products', 'categories', 'sizes']);
}
我的联接表是products_sizes,我使用的是标准约定。 ' Sizes.name' => $ size不会工作。
有任何帮助吗? THX