我第一次在我的网站上设置Auth组件,除了我尝试访问受限制的页面外,一切似乎都正常。我被重定向到http://localhost/MySite/users/login
,而不是被重定向到http://localhost/MySite/users/users/login
,控制器名称会在网址上重复出现。如何解决这个问题?
我正在使用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');
}
答案 0 :(得分:0)
在Auth组件中,您需要添加'unauthorizedRedirect',否则Cake会尝试重定向到/ {app-directory}(这让我昨天头疼)。
public $components = array(
//your other components
'Auth' => array(
//your other options for Auth
'unauthorizedRedirect' => '/home'
)
);
这会指示任何尝试访问不允许访问“yourDomain / home”页面的用户。