Reputation: 6475
I am trying to do pagination from the accommodation controller but with data from the MemberWall model.
here is the code
Accommodation
$data = $this->Accommodation->Member->MemberWall->paginate('MemberWall');
MemberWall
var $paginate = array(
'limit' => 4,
'order' => array(
'MemberWall.created' => 'asc'
)
);
I get this error
SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use nea.... Query: paginate
Thanks, Alex
Upvotes: 4
Views: 9484
Reputation: 6571
The MemberWall $paginate array (your second snippet) looks like it's defined in member_walls_controller.php It will not be accessible from accommodations_controller.php
$this->Accommodation->Member->MemberWall->paginate('MemberWall');
is calling a method on the MemberWall model. paginate() is a controller method.
Read Custom-Query-Pagination, particularly the last section.
I'm not sure that you can paginate that far down a relationship and it indicates to me that you probably need to rethink your datamodel and logic.
The 1.2 manual is better written on this topic.
Upvotes: -2
Reputation: 15838
Here is the REAL answer.
$data = $this->paginate($this->Accommodation->Member->MemberWall);
I had trouble finding this in the docs too. You can actually pass a model object into the paginate method.
Upvotes: 18
Reputation: 131
I've tried and it works in both ways:
$this->paginate('MemberWall');
$this->paginate($this->Accommodation->Member->MemberWall);
In my code I use something like;
$this->loadModel('MemberWall');
$this->paginate = array(.....);
$data = $this->paginate('MemberWall');
Upvotes: 8