Pagination sort link on a virtual field/entity property in CakePHP 3.0

前端 未结 2 1481
灰色年华
灰色年华 2020-12-10 15:53

I want to create a pagination sort link on a virtual field/entity property in CakePHP 3.0.

In CakePHP 2.x I used to create a virtual field, and then create a paginat

2条回答
  •  臣服心动
    2020-12-10 16:52

    Set your default sort order to be the same as your virtual field:

    public $paginate = [
      'order' => [
        'first_name' => 'ASC',
        'last_name' => 'ASC',
      ]
    ];
    

    Then just add the following to your View to prevent the paginator from overriding the default order unless specified by the user:

    if (empty($_GET['direction'])) { $this->Paginator->options(['url' => ['direction' => null, 'sort' => null]]); }
    

提交回复
热议问题