Reputation: 28324
I am using acl and I want to redirect the users based on which group they are from
in my appcaontroller I have this
public function beforeFilter() {
//Configure AuthComponent
//$this->Auth->allow('display');
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'posts', 'action' => 'add');
}
what should I do so if the user is from group_id 1, he/she should be redirected to a place different than group_id = 4 etc
thanks
Upvotes: 0
Views: 990
Reputation: 2985
Okay so for example you are redirecting every user to an action say dashboard
. Instead of redirecting the user to add action of posts
controller redirect to dashboard
of users
controller. I am assuming you have another table for groups and you are keeping it's foreign key in users table.
$this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'dashboard');
The above will redirect user upon login to dashboard
action in users
controller. Now to take every user to a specific group, get the group name of user and redirect to specific page.
function dashboard() {
//get user's group (role)
$group_name = $this->User->Group->field('name', array('id' => $this->Auth->User('group_id')));
//group selection logic here
$action = 'dashboard_' . $group_name;
$this->redirect('controller' => 'users' => 'action' => $action);
}
So the above code will take every user to specific action e.g. if group name is 'managers' user will be redirected to 'managers_dashboard'.
Upvotes: 4