Auth repeats controller in URL

岁酱吖の 提交于 2019-12-24 13:42:38

问题


I am setting for the first time the Auth component on my site, and everything seems to work fine except when I try to access a restricted page. Instead of being redirected to http://localhost/MySite/users/login, I get redirected to http://localhost/MySite/users/users/login, the controller name is repeated on the url. How can this issue be fixed?

I am using CakePhp 2.4.4

AppController

class AppController extends Controller {
public $components = array('DebugKit.Toolbar',
                            'Session','Auth' => array(
                                        'loginRedirect'=> array(
                                            'controller' => 'admins',
                                            'action' => 'admin_index'
                                        ),
                                        'logoutRedirect' => array(
                                            'controller' => 'users',
                                            'action' => 'login' 
                                        ),
                                        'loginAction' => array(
                                            'controller' => 'users',
                                            'action' => 'login',
                                            'plugin' => 'users'
                                        ),
                                        'authError' => 'Não tem permissão para aceder a esta área. Por favor faça login.',
                                        'authenticate' => array(
                                            'Form' => array(
                                                'fields' => array('username' => 'username', 'password' => 'password'
                                                    ),
                                                'userModel' => 'User'
                                            )
                                        ),
                                        'authorize' =>array('Controller'
                                        )
                                    )
                        );

public function beforeFilter(){
    $this->Auth->allow('index','ShowImages','ShowShowbill','ShowVideos','ShowContactUs','contact','login','DisplayMusic','DisplayEntertainment','DisplayPromotion','DisplayStaff','DisplayEquipments');

}

回答1:


In Auth component you need to add 'unauthorizedRedirect' otherwise Cake tries to redirect to /{app-directory} (this was giving me a headache yesterday).

public $components = array(
    //your other components
    'Auth' => array(
        //your other options for Auth
        'unauthorizedRedirect' => '/home'
    )
);

This would direct any user trying to access a page they shouldn't be allowed on to 'yourDomain/home'.



来源:https://stackoverflow.com/questions/23477660/auth-repeats-controller-in-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!