I am using cakephp 2.4 .I am trying to use cake Paginator component.But here Paginator limit not working.I have tried below code in controller.

class TutorialsController extends AppController
    {
        public $components = array('Paginator');
        public $paginate = array(
        'limit' => 3
        );

        public function index()
        {
            $this->Tutorial->recursive =0;
            $this->set('tutorials', $this->Paginator->paginate());
        }

    } 
有帮助吗?

解决方案

Never mix component and controller pagination. Both itself work just fine, but mixing them can cause trouble as you can see.

So either don't include the component and use $paginate alone, or use

$this->Paginator->settings()

inside the actions. You can also directly pass settings in your $components array, as well.

其他提示

class TutorialsController extends AppController
{
    public $components = array('Paginator');
    public $paginate = array(
    'limit' => 3
    );

    public function index()
    {
        $this->Tutorial->recursive =0;
        $this->Paginator->settings = $this->paginate; //This line does the trick. 
        $this->set('tutorials', $this->Paginator->paginate());
    }

} 

And if you need some bootstrap looking for your paginator, check this post out: Bootstrap pagination with CakePHP pagination helper

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top