1

我有行 sql 查询,我想在 cakephp 分页器组件的帮助下对这个查询进行分页。我怎么能?

$q = "SELECT
                `UserList`.`id`,`UserList`.`user_id`,`UserList`.`list_user_id`,
                `User`.`username` ,`User`.`id` ,
                `UserDetail`.`sex`,`UserDetail`.`image`,`UserDetail`.`display_name`,`UserDetail`.`country`,`UserDetail`.`height`,`UserDetail`.`weight`,`UserDetail`.`hair_color`,`UserDetail`.`eye_color`
                from `user_lists` as `UserList` 
                inner join `users` as `User` on `UserList`.`list_user_id` = `User`.`id`
                inner join `user_details` as `UserDetail` on `UserList`.`list_user_id` = `UserDetail`.`user_id`
                where ((`UserList`.`user_id`=".$user_id.") and (`UserList`.`in_list`='short')) order by `UserList`.`created` desc limit 1";
$this->paginate = array(
                'conditions' => /*Pass $q here */,
            'limit' => 15,
            )
        );

提前致谢。

4

1 回答 1

0

你不

这只是行不通,但从问题中的查询来看,您只需要照常使用分页

class UserListsController extends AppController {

    public $paginate = array(
        'contain' => array(
            'User',
            'UserDetail'
        )
    );

    public function index($userId = null) {
        $conditions = array(
            'user_id' => $userId,
            'in_list' => 'short'
        );

        $data = $this->paginate($conditions);
        $this->set('data', $data);
    }

}
于 2013-07-03T09:47:10.917 回答