Posted By

sveggiani on 09/09/10


Tagged

cakephp


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

sebasromano
echo419r
tmmyy


Cakephp: paginate different model than current and using Containable


 / Published in: PHP
 

  1. // Import model inside another
  2. App::Import('Model', 'Example');
  3. $this->Example = new Example;
  4.  
  5. // add options to paginate the model
  6. $this->paginate['Example'] = array( 'limit' => 5, 'page' => 1 , 'order' => 'Example.name' );
  7. $this->set( 'items', $this->paginate('Example') );
  8.  
  9.  
  10.  
  11.  
  12. // using containable
  13. $this->Issue->IssuesSerialNumber->Behaviors->attach('Containable');
  14. $this->paginate['IssuesSerialNumber'] = array('limit' => 15, 'page' => 1, 'contain' => array('Issue', 'SerialNumber', 'SerialNumber.Product'), 'order' => 'IssuesSerialNumber.serial_number_id', 'conditions' => array('IssuesSerialNumber.issue_id' => $this->Session->read('Issue.id') ) );
  15.  
  16. $items = $this->paginate( 'IssuesSerialNumber' );

Report this snippet  

You need to login to post a comment.