开发者

Auth Component redirects automatically in cakePHP

开发者 https://www.devze.com 2023-01-09 23:40 出处:网络
After adding Auth component while accessing the home page it redirects to login page ie., let www.domain.com is my url.

After adding Auth component while accessing the home page it redirects to login page

ie., let www.domain.com is my url.

After adding the auth component when i try to access www.domain.com it redirects to www.domain.com/logins/login.

how can i avoid this initial redirection??

i already given a route as below

Router::connect('/', array(
    'controller' => 'pages', 'action' => 'display', 'home'
));

but开发者_JAVA技巧 no use

thankz in advance


In your pages_controller.php (if you don't already have one in app/controllers, copy the one from cake/libs/controller:

function beforeFilter()
{
    parent::beforeFilter();
    $this->Auth->allow('*');
}


In AppController::beforeFilter() add the following:

$this->Auth->allowedActions = array('display');

UPDATE: allowedActions are controller actions for which user validation is not required. http://api.cakephp.org/2.4/source-class-AuthComponent.html#228-234


You could also just add this code to your users controller to stop it from automatically redirecting, but like everyone else said, you should also allow display.

function beforeFilter() {
    ...
    $this->Auth->autoRedirect = false;
}

http://book.cakephp.org/view/395/autoRedirect

0

精彩评论

暂无评论...
验证码 换一张
取 消