【问题标题】:How to sort associated table data?如何对关联的表数据进行排序?
【发布时间】:2012-04-12 16:30:33
【问题描述】:

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

但是对产品进行排序不起作用。

【问题讨论】:

    标签: cakephp pagination cakephp-1.3


    【解决方案1】:
    <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>
    

    【讨论】:

      猜你喜欢
      • 2016-02-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-02
      • 1970-01-01
      • 2019-08-10
      • 2013-05-19
      相关资源
      最近更新 更多