2012-04-11 23 views
0

私はgroup_idをユーザに割り当てましたが、ユーザのインデックスページでは、ユーザが所属する特定のグループに属するユーザをどのようにしたいのですか。 現在そのセットにはすべてのユーザーを表示するにはグループ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.'); 
     } 
    } 
} 

おかげ

+0

ユーザーはどのようにログインしていますか? aclの – Wylie

+0

。私は – Autolycus

+0

質問にログイン機能を追加しました – Autolycus

答えて

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

} 

希望があれば

関連する問題