Cakephp分页不适用于HABTM

时间:2014-04-17 08:35:27

标签: php cakephp has-and-belongs-to-many

所以我有2个模特

表演者模特:

class Performer extends AppModel {
    public $actsAs = array('Containable');
    var $name = 'Performer';
    var $hasAndBelongsToMany = array('Genre');
}

类型模型:

class Genre extends AppModel {
    var $actsAs = array('Tree');
    var $hasAndBelongsToMany = array('Performer');
}

控制器操作:

public function admin_index(){

     $this->paginate = array(
                    'limit' => 24,
                    'contain' => array(
                    'Genre')); 

     $performers = $this->paginate();              

     $this->set('performers',$performers);
     $this->autoRender = true;
     $this->layout = 'default';
}

查看:

<table>
 <tr>
 <th><?= $this->Paginator->sort('id', 'ID') ?></th>
 <th><?= $this->Paginator->sort('name', 'Name') ?></th>
    <th><?= $this->Paginator->sort('Genre.name', 'Genre') ?></th>
 </tr>
   <?php foreach ($performers as $performer): ?>
 <tr>
    <td><?= $performer['Performer']['id'] ?> </td>
    <td><?= h($performer['Performer']['name']) ?> </td>
    <td><?= $performer['Genre'][0]['name'] ?> </td>
</tr>
<?php endforeach; ?>
</table>

问题:当我使用$this->Paginator->sort('Genre.name', 'Genre');时,我会收到: 错误:SQLSTATE [42S22]:找不到列:1054'order clause'中的未知列'Genre.name'

如何使用HABTM按Genre.name排序?

0 个答案:

没有答案