Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cakephp - Paginating data from another model

Tags:

find

cakephp

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

like image 465
Alex Avatar asked Nov 29 '22 10:11

Alex


2 Answers

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');

like image 33
TheTambu Avatar answered Dec 01 '22 01:12

TheTambu


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.

like image 99
Alex K Avatar answered Dec 01 '22 00:12

Alex K