I have two models: storeregions and stores.
//models
<?php
class Store extends AppModel
{
var $name = 'Store';
var $belongsTo = 'Storeregion';
}
?>
<?php
class Storeregion extends AppModel
{
var $name = 'Storeregion';
var $hasMany = 'Store';
}
?>
//controller:
<?php
class AdminsController extends AppController
{
var $name = 'Admins';
var $paginate = array(
'Store' => array ('limit' => 25, 'order' => array('Store.name'
=> 'asc')) ,
'Storeregion' => array ('limit' => 25, 'order' =>
array('Storeregion.name' => 'asc'))
);
function view_stores()
{
$defaultModelToSortBy = 'Store';
if ( isset($this->params["named"]) && !empty($this-
>params["named"]) )
{
$modelNFieldNameToSortyBy =
$this->params["named"]["sort"] ; //
Modelname.fieldname
$arrModelNFieldName = explode(".",
$modelNFieldNameToSortyBy);
$defaultModelToSortBy = (count($arrModelNFieldName) ==
2) ?
$arrModelNFieldName[0] : $defaultModelToSortBy;
}
$data = $this->paginate($defaultModelToSortBy);
$this->set(compact('data'));
}
?>
//view:
<table>
<tr>
<th><?php echo
$paginator->sort('Region',
'Storeregion.name');?></th>
<th><?php echo $paginator->sort('Store
No.',
'Store.storenumber');?></th>
<th><?php echo $paginator->sort('Name',
'Store.name');?></
th>
<th><?php echo $paginator->sort('City',
'Store.city');?></
th>
<th><?php echo $paginator->sort('State',
'Store.statecode');?></th>
<th><?php echo $paginator->sort('Zip',
'Store.zipcode');?
></th>
</tr>
<?php if ($defaultModelToSortBy ==
"Store"): foreach($data as
$store): ?>
<tr>
<td><?php echo
$store['Storeregion']['name']; ?></td>
<td><?php echo
$store['Store']['storenumber']; ?></td>
<td><?php echo $store['Store']['name'];
?></
td>
<td><?php echo $store['Store']['city'];
?></td>
<td><?php echo
$store['Store']['statecode']; ?></td>
<td><?php echo
$store['Store']['zipcode']; ?></
td>
</tr>
<?php endforeach; endif; ?>
<?php if ($defaultModelToSortBy ==
"Storeregion"):
foreach($data as $store): ?>
<? foreach($store["Store"] as
$singleStore): ?>
<tr>
<td>
<?php echo
$store['Storeregion']['name']; ?></td>
<td><?php echo
$singleStore['storenumber']; ?></td>
<td><?php echo $singleStore['name'];
?></td>
<td><?php echo $singleStore['city'];
?></td>
<td><?php echo
$singleStore['statecode']; ?></td>
<td><?php echo $singleStore['zipcode'];
?></
td>
</tr>
<?php endforeach;?>
<?php endforeach; endif; ?>
<tr>
<td
colspan="3"><?=$paginator->prev('<< Previous ', null,
null, array('class' => 'disabled'));?></td>
<td
colspan="3"><?=$paginator->next(' Next >>', null, null,
array('class' => 'disabled'));?></td>
</tr>
<tr>
<td colspan="6"><?=
$paginator->counter(); ?></td>
</tr>
</table>
So as you can see i have figured out how to do the controller and the
view but the problem is that if one region has 90 stores, than all 90
stores are show on the page 1 :-(
Is there a right way to do this ?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---