Ho Domink, maybe this link can help you:
http://stackoverflow.com/questions/1694047/cakephp-pagination-with-conditions- on-has-many On the first glance it looks like somebody has the same problem. Anja Am Samstag, 23. April 2011, um 23:47:26 schrieb Dominik Gajewski: > Hi. > I have problem with pagination. Everything is working till i don't > want sort byt admission date. I think is only need to add one line of > code in $var paginate. Or maybe that is problem becasue UserData > hasMany MainBook and i want select only this one which is empty in > field MainBook.extract_date > > Could you help me? > > I have tables in database > > user_datas > ============ > id > user_id > name > sName > surname > birthDate > sex > nationality > pesel > > main_books > ============ > id > year > baby_id > user_data_id > admission_date > admission_mode > extract_date > extract_mode > doctor_id > > Model MainBook > =============== > class MainBook extends AppModel{ > var $name = 'MainBook'; > > var $belongsTo = array( > 'UserData' => array( > 'className' => 'UserData', > 'foreignKey' => 'user_data_id' > ) > ); > } > > Model UserData > =============== > class UserData extends AppModel{ > var $name = 'UserData'; > var $hasMany = array( > 'MainBook' => array( > 'className' => 'MainBook', > 'foreignKey' => 'user_data_id' > ), > ); > } > > MainBooksController > =============== > class MainBooksController extends AppController{ > > var $name = 'MainBooks'; > > var $paginate = array( > 'limit' => 20, > 'order' => array( > 'UserData.surname' => 'asc', > ), > 'conditions' => array( > 'User.status' => '1' > ), > ); > > > function show_current(){ > /** > Menu i kontrola sesji > */ > $s = $this->sesionCheck(2); > $m = $this->menu($s); > $this->set('menu', $m); > > $data = $this->paginate('UserData'); > $this->set('data', $data); > > > } > } > > My view show_current.ctp > <table> > <tr> > <th><?php echo $this->Paginator->sort('Name', 'UserData.name'); ?></th> > <th><?php echo $this->Paginator->sort('Surname', 'UserData.surname'); > ?></th> <th><?php echo $this->Paginator->sort('PESEL', 'UserData.pesel'); > ?></th> <th><?php echo $this->Paginator->sort('Admission Date', > 'MainBook.admission_date'); ?></th? > </tr> > <?php foreach($data as $val): ?> > <tr> > <td><?php echo $val['UserData']['name']; ?> </td> > <td><?php echo $val['UserData']['surname']; ?> </td> > <td><?php echo $val['UserData']['pesel']; ?> </td> > <td><?php echo $val['MainBook'][0]['admission_date']; ?> </td> > </tr> > <?php endforeach; ?> > </table> -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php
