0

I have a group_id assigned to the user but at my users index page I want to how users that belong to the specific group that the logging user belongs to. currently its set to show all users

public function index() {

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

how would I change that

login:

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

thanks

2
  • How are the users being logged in?
    – Wylie
    Apr 11, 2012 at 1:31
  • added login function to the question
    – Asim Zaidi
    Apr 11, 2012 at 1:39

1 Answer 1

2

To get the group_id of the currently logged in user, update the index() action to include:

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

}

Hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.