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 に答える