我的想法是这样的。我在这样的模型中创建了一个函数。
public function status($id = null)
{
$conditions = array('Transaction.catalogue_id' => $id);
$status = $this->find('first',array('conditions' => $conditions, 'fields' => array('Transaction.status'),'order' => array('Transaction.id' => 'desc'))
);
return $status['Transaction']['status'];
}
我如何从这个循环中发送 $id 的值?
<table cellspacing="0" cellpadding="0" border="0" class="all">
<thead>
<tr>
<th>No</th>
<th>Title</th>
<th>Author</th>
<th>ISBN</th>
<th>Location</th>
<th>Availability</th>
</tr>
</thead>
<?php $count = 1;?>
<tbody>
<?php foreach ($Catalogue as $Catalogue): ?>
<tr>
<td><?php echo $count++; ?></td>
<td><?php echo $this->Html->link($Catalogue['Catalogue']['title'],array('controller' => 'transactions', 'action' => 'view',$Catalogue['Catalogue']['id']),array('escape' => false, 'class' => 'ajax')); ?></td>
<td><?php echo $Catalogue['Catalogue']['author']; ?></td>
<td><?php echo $Catalogue['Catalogue']['isbn']; ?></td>
<td><?php echo $Catalogue['Location']['rack']; ?></td>
<td><?php echo $this->getstatus($Catalogue['Catalogue']['id'])</td>
</tr>
<?php endforeach; ?>
</tbody>
<?php unset($Catalogue); ?>
</table>
我们可以做 $this->getstatus($Catalogue['Catalogue']['id']) 吗?