CakePHP - pagination with another model

I am trying to paginate from a placement controller, but with data from a 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

+3
source share
4 answers
  • The array of the MemberWall $ element (your second fragment) looks like it is defined in member_walls_controller.php. It will not be available from accommodation_controller.php

  • $this->Accommodation->Member->MemberWall->paginate('MemberWall');calls a method in the MemberWall model. paginate () is a controller method.

  • Read Custom-Query-Pagination , especially the last section.

  • I'm not sure that you can break this far into relationships, and this tells me that you probably need to rethink your data and logic.

  • 1.2 .

-2

.

$data = $this->paginate($this->Accommodation->Member->MemberWall);

. paginate.

+16

I have tried and works 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');

+8
source

$ this-> paginated ('MemberWall'); iirc is the way it works.

0
source

Source: https://habr.com/ru/post/1789797/


All Articles