【问题标题】:Paginate table with HasMany relation in cakephp 3 betacakephp 3 beta中具有HasMany关系的分页表
【发布时间】:2015-01-21 11:34:21
【问题描述】:

我有带有 (group_id,member_id,city_id) 字段的广告表。这是我的 GroupsController->view 方法。

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]

怎么了?

【问题讨论】:

    标签: has-many pagination cakephp-3.0


    【解决方案1】:

    magic property getters 返回\Cake\ORM\Association 实例,如果您需要实际的\Cake\ORM\Table 对象,请使用Association::target()

    $this->Groups->Advertisements->target()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-08
      相关资源
      最近更新 更多