CakePhp AngularJs 分页

CakePhp AngularJs pagination

我开始学习 CakePhp 和 AngularJs,我想让分页工作。

我找到了这个简单的教程:http://florian-kraemer.net/2015/10/cakephp-angularjs-pagination/ 但我无法使用它。

这是示例中的代码:

public function index() {

    $query = $this->Table->find();
    if (empty($this->request->params['paging'][$this->Table->alias()])) {
       $paging = false;
    } else {
       $paging = $this->request->params['paging'][$this->Table->alias()];
    }
    $this->set('records', $this->paginate($query));
    $this->set('paging', $paging);
    $this->set('_serialize', ['records', 'paging']);
}

我的模型称为 Entry,我必须如何更改代码才能使此示例正常工作,我这样尝试但它不起作用:

public function index() {

    $query = $this->Entry->find();
    if (empty($this->request->params['paging'][$this->Entry->alias()])) {
       $paging = false;
    } else {
       $paging = $this->request->params['paging'][$this->Entry->alias()];
    }
    $this->set('records', $this->paginate($query));
    $this->set('paging', $paging);
    $this->set('_serialize', ['records', 'paging']);
}

我不确定要更改我的代码以使其正常工作。任何帮助将不胜感激。

谢谢,格雷戈尔

请试试这段代码,应该可以。你必须在 paginate 之后声明 $paging。

public function index() {

    $query = $this->Entry->find();
    $this->paginate($query);
    if (empty($this->request->params['paging'][$this->Entry->alias()])) {
       $paging = false;
    } else {
       $paging = $this->request->params['paging'][$this->Entry->alias()];
    }
    $this->set(compact('records', 'paging'));
    $this->set('_serialize', ['records', 'paging']);
}