Saturday, April 23, 2011

Pagination hasMAny

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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate