cakephp 使用分页和顺序

标签 cakephp

嗨, 为什么不使用“订单”功能?

$this->paginate = array(
                'limit' => 5,
                'order' => array(
                    'User.name' => 'desc'
                ),
                'fields' => array('Post.id', 'Post.title', 'User.name AS aut_name'),                        
                'joins' => array(
                    array(
                        'table' =>'users',
                        'alias' =>'User',
                        'type' =>'LEFT',
                        'conditions' => array(
                            'Post.user_id = User.user_id'
                        )
                    )
                )
        );  

        $posts = $this->paginate();
        $this->set(compact('posts'));

数据库结构:

posts:
id, title,body, created, updated, user_id

users:
user_id, name

最佳答案

快速查看您的代码... User 表中是否存在字段 user_id ?

'conditions' => array(
    'Post.user_id = User.id'
)

关于cakephp 使用分页和顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5016110/

相关文章:

javascript - CakePHP 3.x - 编辑 : Dates having empty fields upon submission despite them already existing

mysql - foreach 不打印 cakephp 中的查询结果

CakePHP 多对多带条件

php - CakePHP 1.3查询问题

php - 将日期设置为列表 Cakephp 3 中的 keyField

php - 如何获取cakephp中的基本Url?

authentication - CakePHP 3 "Login As"具有多个身份验证 session

php - MySQL:允许通过表单提交PHP代码和SQL语句

php - CakePHP 管理面板

mysql - Cakephp 查找或条件不工作