0
votes

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 linkthaJeztah

1 Answers

0
votes

Try this in your Controller:

public function index() {
  $this->paginate = array('limit'=>5);
  $this->set('yourVariableNameHere', $this->paginate());
}