0

我有一个 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.');
        }
    }
}

谢谢

4

1 回答 1

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'));

}

希望有帮助。

于 2012-04-11T06:18:24.437 回答