2012-04-12 75 views
1

我必须显示列表中有一个关系表数据。我正在为列表视图使用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> 

但分拣产品不能正常工作。

+0

显示你的代码,请。 – JJJ 2012-04-12 05:47:58

+0

添加了代码。 – Vins 2012-04-12 06:11:43

回答

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>