Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP admin section routing and redirecting

Tags:

php

cakephp

I'm struggling with the concept of creating an admin section in CakePHP-project. (version 2.3.5)

I have uncommented the line in Config/core.php:

Configure::write('Routing.prefixes', array('admin'));

I have added the line in Config/routes.php: (Just as they advice to do in CakePHP cookbook.)

Router::connect('/admin', array('controller'=>'pages', 'action'=>'index','admin' => true));

In AppController.php I have the following:

    public $components = array(
    'Session',
    'Auth' => array(
        'loginRedirect'=>array('controller'=>'pages','action'=>'index', 'admin'=>true),
        'logoutRedirect'=>array('controller'=>'pages','action'=>'display','home'),
        'authError'=>'you have no access.',
        'authorize'=>array('Controller')
    )
);

Then I have added a layout View/Pages/admin_index.ctp which is where I want to be redirected after login. I managed to get my login working in UsersController.php.

So the question is, where should I redirect in AppController.php to get my logged admin to the admin_view? I believe that loginRedirect is somehow broken..

I have studied some tutorials on this subject but I have found only this Youtube-video http://www.youtube.com/watch?v=zvwQGZ1BxdM All other tutorials seem to be concerning earlier versions of CakePHP.

like image 932
hemppa Avatar asked May 29 '13 17:05

hemppa


1 Answers

I guess you could set a loginAction in AppController and then inside this action you could do:

$this->redirect(array('controller'=>'someController','action'=>'someAction','admin'=>true));
like image 163
CrsLand Avatar answered Nov 06 '22 09:11

CrsLand