我有(group_id,member_id,city_id)字段的广告表。这是我的GroupsController->视图方法。
public function view($id = null) {
$group = $this->Groups->get($id);
$this->paginate = ['conditions'=>['group_id'=>$id] , 'contain'=>['Members', 'Cities']];
$advertisements = $this->paginate($this->Groups->Advertisements);
$this->set(compact('group' , 'advertisements'));
}
除了真实结果外,它还会生成此警告。
Warning (4096): Argument 1 passed to Cake\Controller\Component\PaginatorComponent::validateSort() must be an instance of Cake\ORM\Table, instance of Cake\ORM\Association\HasMany given, called in D:\xampp\htdocs\project\vendor\cakephp\cakephp\src\Controller\Component\PaginatorComponent.php on line 153 and defined [CORE\src\Controller\Component\PaginatorComponent.php, line 301]
有什么问题?
答案 0 :(得分:3)
magic property getters返回\Cake\ORM\Association
个实例,如果您需要实际的\Cake\ORM\Table
对象,请使用Association::target()
。
$this->Groups->Advertisements->target()