【问题标题】:sorting and pagination cakephp排序和分页 cakephp
【发布时间】:2012-05-10 15:19:14
【问题描述】:

在我的控制器中我有这个

public function station_users($id=null){
        $users = $this->User->find('all',array('conditions'=>array('test_id'=>$this->params['named']['test_id'])));

        $this->set('users', $users);
        $this->render("station_users",'ajax');
    }

我正在为某个测试 ID 获取所有用户,但现在我的排序不起作用。如何添加分页。 我试过了

$this->User->recursive = 0;
        $this->set('users', $this->paginate());

那没用 谢谢

【问题讨论】:

  • 现在效果如何?您的视图设置是否正确以处理分页?

标签: cakephp cakephp-1.3 cakephp-2.0 cakephp-2.1


【解决方案1】:

在调用$this->paginate() 之前,您需要配置分页,如下所示:

$this->paginate = array
    (
        'User' => array
        (
            'recursive' => 0,
            'conditions' => array
            (
                'test_id' => $this->params['named']['test_id'],
            ),
        )
    );

$users = $this->paginate('User');

Cookbook 是您的朋友,请尽可能使用它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-10
    • 2012-03-08
    • 2013-09-28
    • 2012-08-16
    • 2016-06-12
    相关资源
    最近更新 更多