如何在蛋糕php重定向主页

时间:2014-04-25 20:17:27

标签: cakephp

在我的蛋糕php网站上,登录页面重定向到结果显示页面后,我需要重定向主页。这是AppController.php代码:

class AppController extends Controller {

    public $components = array(
        'Session',
        'Auth' => array(
            'loginRedirect' => array('controller' => 'results', 'action' => 'add'),

            'logoutRedirect' => array('controller' => 'users', 'action' => 'login')
        ),
        'Security'
    );

}

1 个答案:

答案 0 :(得分:2)

只需定义loginRedirect

即可

要强制用户在登录后重定向到的位置,只需更改loginRedirect

即可
class AppController extends Controller {

    public $components = array(
        'Session',
        'Auth' => array(
            'loginRedirect' => '/', # <-
            'logoutRedirect' => array('controller' => 'users', 'action' => 'login')
        ),
        'Security'
    );
}

请注意,通常a user is redirected to whatever url they were attempting to access - 默认为/;因此,从Auth组件配置中删除loginRedirect键可能更合适。

相关问题