CakePHP管理部分路由和重定向

编程入门 行业动态 更新时间:2024-10-24 20:13:24
本文介绍了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视频www.youtube/watch?v=zvwQGZ1BxdM 所有其他教程似乎都与CakePHP的早期版本有关。

I have studied some tutorials on this subject but I have found only this Youtube-video www.youtube/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管理部分路由和重定向

本文发布于:2023-10-31 16:35:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546652.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   重定向   CakePHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!