Question

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());
        }

    } 
Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top