Cakephp: paginate different model than current and using Containable


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.