【问题标题】:Difference between $this->paginate() and $this->Paginator->paginate()$this->paginate() 和 $this->Paginator->paginate() 的区别
【发布时间】:2018-12-21 07:47:14
【问题描述】:

除了语法,在 CakePHP 2 中使用 $this->paginate()$this->Paginator->paginate() 有什么区别?

使用一个比另一个有什么优势吗?

【问题讨论】:

    标签: cakephp cakephp-2.0


    【解决方案1】:

    open source, you can take a看:

    public function paginate($object = null, $scope = array(), $whitelist = array()) {
        return $this->Components->load('Paginator', $this->paginate)->paginate($object, $scope, $whitelist);
    }
    

    所以控制器的paginate() 只是一个包装器。好处是控制器方法似乎加载了Paginator 组件,因此您的控制器可以跳过显式加载。

    【讨论】:

      【解决方案2】:

      Controller::paginate() 方法使用Controller::$paginate 属性。

      Controller::$paginate 被特别删除,以支持使用 PaginatorComponent。

      https://github.com/cakephp/cakephp/pull/857#issuecomment-8670695

      PaginatorComponent::paginate() 方法使用PaginatorComponent::$paginate 属性。如果你需要在同一个控制器的多个方法中使用分页,并且需要使用不同的分页设置,那么最好使用组件进行分页。

      无论如何Don’t mix controller and component pagination

      ...如果你混合控制器分页设置并调用分页组件,它很容易适得其反,因为这两个不同 设置并不总是像您期望的那样合并

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-04-07
        • 1970-01-01
        • 2010-11-06
        • 2011-04-12
        • 2013-10-23
        • 1970-01-01
        相关资源
        最近更新 更多