1
votes

I have done admin routing for my admin panel. Right now the url is localhost/app/admin.

Now I have 2 Tables Admins and Users.

I have created an url for the login localhost/app/admin/admins/login.

The page prompts for a username and a password.

But the Problem is when create component in appcontroller with loginredirect it is redirected to localhost/app/admin/users/login.I don't know why. I even tried changing the loginredirect path but it's nothing worked.

This is my appcontroller.php :

public $components = array(
    'Session',
    'Auth' => array(
        'loginRedirect' => array('controller' => 'admins', 'action' => 'add'),
        'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home')
    )
);

public function beforeFilter() {
    $this->Auth->allow('index', 'view');
}

Even if I delete the user table, it redirects to the users login.

1

1 Answers

0
votes

It sounds like your Auth component isn't working. instead of adding the auth redirects into the components variable, put them in your beforeFilter(). Your appController should be:

    public $components = array('Auth','Session');

    public function beforeFilter()
{
    $this->Auth->loginRedirect = array('action' => 'add', 'controller' => 'admins');
    $this->Auth->logoutRedirect = array('controller' => 'pages', 'action' => 'display', 'home');
    $this->Auth->authError = 'You are not allowed to see that.';

}

Are you logging in successfully? if so, check routes.php to make sure you're routing things correctly. this could be tested by trying to navigat to example.com/admins/add manually.