문제

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