Вопрос

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