0

I have a model and i want to paginate its data. all i do is, creating a model, something like this,

class MyModel extends AppModel {}

and include Paginator component in my controller and use it, something like this,

class MyControllers extends AppController
{
public $components = array('Paginator');

public function index()
{
$this->paginate['MyModel'] = array('limit'=>5);
print_r($this->paginate('MyModel'));
}
}

And I have a table with my_controllers name and it has 10 records. if everything was fine, the paginator component must give me 5 records for page one and 5 records for page 2. but it gives me 10 records without any paging.

What is the problem? :(

Thank you

1
  • I don't see a problem in this code (haven't tested it though). However, this is probably not your actual code, I really advise you to add the relevant parts of your actual code as well, as the problem may be somewhere in that code. You can add it to your question by clicking the edit link
    – thaJeztah
    Apr 28, 2013 at 7:52

1 Answer 1

0

Try this in your Controller:

public function index() {
  $this->paginate = array('limit'=>5);
  $this->set('yourVariableNameHere', $this->paginate());
}
1
  • Thank you, Thank you so much. Thank you sir. You solved my problem. Thank you. I don't know why $paginate property does not work! if I set $property on the fly as you said the pagination will works fine. Why?
    – user771425
    Apr 29, 2013 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.