我得到一個Item
模型belongsTo
a Category
,ergo Category
hasMany
Item
。CakePHP find hasMany associated model
from CategoriesController
我想獲取所有Item
的分類。
我嘗試這樣做,但它不工作:
if($id == null) {
throw new NotFoundException(__('404'));
}
$this->Category->id = $id;
if(!$this->Category->exists()) {
throw new NotFoundException(__('404'));
}
$items = $this->Category->Item->find();
$this->set('items',$items);