|
Hi i have prefixes like "admin", "student" and i need to use prefixed dashboards (/admin/users/dashboard, /student/users/dashboard) here my working code AppController.php function beforeFilter() { $this->__checkAuth(); $this->layout = $this->__setLayout(); } function __checkAuth() { $this->Auth->authorize = array('Actions' => array('actionPath' => 'controllers')); $this->Auth->loginAction = '/users/login'; $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login'); $this->Auth->loginRedirect = '/users/dashboard'; $this->Auth->redirect = false; $loggeduser = $this->User->findById($this->Auth->user('id')); $this->Session->write('loggeduser', $loggeduser); } UsersController.php public function dashboard() { $this->layout = 'user'; $prefixes = Configure::read('Routing.prefixes'); $loggeduser = $this->Session->read('loggeduser'); if (in_array($loggeduser['Group']['name'], $prefixes)) { $this->redirect('/'.$loggeduser['Group']['name'].'/users/dashboard'); } } is it ok? or you suggest to use another logic thanks in advance Baurzhan Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [hidden email] For more options, visit this group at http://groups.google.com/group/cake-php |
|
You could check the prefixes in your login() method and don one less
redirect. Something like: public function login() { if ($user = $this->Auth->user()) { $prefixes = Configure::read('Routing.prefixes'); if (in_array($user['Group']['name'], $prefixes)) { $this->redirect(array( 'prefix' => $use['Group']['name'], 'controller' => 'users', 'action' => 'dashboard' )); } } } Notice I passed a route array instead of a string. This way, if you ever want the URL to have a different format it will still work. On Wed, May 23, 2012 at 5:21 AM, baur79 <[hidden email]> wrote: > Hi > i have prefixes like "admin", "student" > and i need to use prefixed dashboards (/admin/users/dashboard, > /student/users/dashboard) > here my working code > > AppController.php > > function beforeFilter() { > $this->__checkAuth(); > $this->layout = $this->__setLayout(); > } > > function __checkAuth() { > $this->Auth->authorize = array('Actions' => array('actionPath' => > 'controllers')); > $this->Auth->loginAction = '/users/login'; > $this->Auth->logoutRedirect = array('controller' => 'users', > 'action' => 'login'); > $this->Auth->loginRedirect = '/users/dashboard'; > $this->Auth->redirect = false; > > $loggeduser = $this->User->findById($this->Auth->user('id')); > $this->Session->write('loggeduser', $loggeduser); > > } > > > UsersController.php > > public function dashboard() { > $this->layout = 'user'; > > $prefixes = Configure::read('Routing.prefixes'); > $loggeduser = $this->Session->read('loggeduser'); > if (in_array($loggeduser['Group']['name'], $prefixes)) { > $this->redirect('/'.$loggeduser['Group']['name'].'/users/dashboard'); > } > } > > > is it ok? or you suggest to use another logic > > thanks in advance > Baurzhan > > -- > Our newest site for the community: CakePHP Video Tutorials > http://tv.cakephp.org > Check out the new CakePHP Questions site http://ask.cakephp.org and help > others with their CakePHP related questions. > > > To unsubscribe from this group, send email to > [hidden email] For more options, visit this group at > http://groups.google.com/group/cake-php -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [hidden email] For more options, visit this group at http://groups.google.com/group/cake-php |
| Powered by Nabble | Edit this page |
