如何根据组ID获取列表

时间:2012-04-11 01:28:39

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

我有一个group_id分配给用户但在我的用户索引页面我想知道属于该日志记录用户所属的特定组的用户。 目前它的设置显示所有用户

public function index() {

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

我该怎么改变

登录:

public function login() {
     if ($this->request->is('post')){
        if ($this->Auth->login()) {
            $this->redirect($this->Auth->redirect());
        }else {
            $this->Session->setFlash('Your username or password was incorrect.');
        }
    }
}

感谢

1 个答案:

答案 0 :(得分:2)

要获取当前登录用户的group_id,请更新index()操作以包括:

public function index() {

    // get logged in user info
    $user = $this->Auth->user();
    $group_id = $user['group_id'];

    // add pagination conditions
    $this->paginate = array(
        'conditions' => array('User.group_id' => $group_id)
    );
    $this->User->recursive = 0;
    $this->set('users', $this->paginate('User'));

}

希望有所帮助。