CakePHP管理部分路由和重定向 [英] CakePHP admin section routing and redirecting

查看:143
本文介绍了CakePHP管理部分路由和重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了在CakePHP-project中创建管理部分的概念。 (版本2.3.5)

I'm struggling with the concept of creating an admin section in CakePHP-project. (version 2.3.5)

我已取消注释Config / core.php中的行:

I have uncommented the line in Config/core.php:

Configure::write('Routing.prefixes', array('admin'));

我已经在Config / routes.php中添加了这一行:(就像他们在CakePHP Cookbook。)

I have added the line in Config/routes.php: (Just as they advice to do in CakePHP cookbook.)

Router::connect('/admin', array('controller'=>'pages', 'action'=>'index','admin' => true));

在AppController.php中有以下内容:

In AppController.php I have the following:

    public $components = array(
    'Session',
    'Auth' => array(
        'loginRedirect'=>array('controller'=>'pages','action'=>'index', 'admin'=>true),
        'logoutRedirect'=>array('controller'=>'pages','action'=>'display','home'),
        'authError'=>'you have no access.',
        'authorize'=>array('Controller')
    )
);

然后我添加了一个布局视图/ Pages / admin_index.ctp这是我想重定向登录后。我设法让我的登录工作在UsersController.php。

Then I have added a layout View/Pages/admin_index.ctp which is where I want to be redirected after login. I managed to get my login working in UsersController.php.

所以问题是,我应该在AppController.php中重定向,以获取我的登录管理员到admin_view?我相信loginRedirect是有点破坏。

So the question is, where should I redirect in AppController.php to get my logged admin to the admin_view? I believe that loginRedirect is somehow broken..

我研究了一些关于这个主题的教程,但我发现只有这个YouTube视频http://www.youtube.com/watch?v=zvwQGZ1BxdM 所有其他教程似乎都与CakePHP的早期版本有关。

I have studied some tutorials on this subject but I have found only this Youtube-video http://www.youtube.com/watch?v=zvwQGZ1BxdM All other tutorials seem to be concerning earlier versions of CakePHP.

推荐答案

我想你可以在AppController中设置一个loginAction,然后在这个动作中你可以这样做:

I guess you could set a loginAction in AppController and then inside this action you could do:

$this->redirect(array('controller'=>'someController','action'=>'someAction','admin'=>true));

这篇关于CakePHP管理部分路由和重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆