如何对关联的表数据进行排序?

时间:2012-04-12 05:44:55

标签: cakephp pagination cakephp-1.3

我要在列表中显示一个关系表数据。我正在使用CakePHP分页和搜索功能进行列表视图。所有其余的功能都运行正常,但我无法为相关的表字段提供排序功能。

我正在使用

<th><?php echo $this->Paginator->sort('First Name','Enrollment.first_name');?></th>
<th><?php echo $this->Paginator->sort('Last Name','Enrollment.last_name');?></th>
<th><?php echo $this->Paginator->sort('Product','Product.name');?></th>

但是对产品进行分类是行不通的。

1 个答案:

答案 0 :(得分:0)

<th><?php echo $this->Paginator->sort('First Name','Enrollment.first_name');?></th>
<th><?php echo $this->Paginator->sort('Last Name','Enrollment.last_name');?></th>
<th><?php echo $this->Paginator->sort('Product','Product.name');?></th>

.....

<td>
   <?php echo $this->Html->link($YOURVAR['Enrollment']['first_name'], array('controller' => 'enrollments', 'action' => 'view', $YOURVAR['Enrollment']['id'])); ?>
</td>
<td>
  <?php echo $this->Html->link($YOURVAR['Enrollment']['title'], array('controller' => 'enrollments', 'action' => 'view', $YOURVAR['Enrollment']['id'])); ?>
</td>
<td>

  // Checkout this line that you change the line as following
  <?php echo $this->Html->link($YOURVAR['Product']['name'], array('controller' => 'products', 'action' => 'view', $YOURVAR['Product']['id'])); ?>
</td>