加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

Cakephp分页与连接表字段排序不工作

发布时间:2020-12-13 13:58:01 所属栏目:PHP教程 来源:网络整理
导读:连接表排序的Cakephp分页不适用于连接表字段.但是对于自定义的sql join查询工作正常.请帮我出来 看下面的示例代码..我有Artist.name连接表字段顺序. $this-paginate = array( 'fields' = array( 'id','Song.title','Song.date','Artist.id AS artist_id','Ar
连接表排序的Cakephp分页不适用于连接表字段.但是对于自定义的sql join查询工作正常.请帮我出来

看下面的示例代码..我有Artist.name连接表字段顺序.

$this->paginate = array(
        'fields' => array(
            'id','Song.title','Song.date','Artist.id AS artist_id','Artist.name AS artist_name','COUNT(SongViews.id) AS views'
        ),'group' => array('ArtistsSong.song_id'),'recursive' =>  0,'limit' =>  20,'joins' => array(
            array(
                'table' => 'tbl_artists_songs','alias' => 'ArtistsSong','conditions'=> array('Song.id = ArtistsSong.song_id')
            ),array(
                'table' => 'tbl_artists','alias' => 'Artist','conditions'=> array('Artist.id = ArtistsSong.artist_id')
            ),array(
                'table' => 'tbl_song_views','alias' => 'SongViews','type' => 'left','conditions'=> array('SongViews.song_id = ArtistsSong.song_id')
            ),),'order' => array('Artist.name'=>'asc')

    );
这是CakePHP中的一个错误.

但是,有一个诀窍来做到这一点.

您应该在主模型中添加一个虚拟字段.

假设你的主要模式是歌曲,你应该在调用分页之前添加它:

$this->Song->virtualFields = array(
    'artist_name' => 'Artist.name'
);

现在,您可以按artist_name排序.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读