我正在使用CakePHP 2.0作为网站的一个小管理部分。如果用户登录正确,我会将他们重定向到管理员仪表板。我这样做如下:
$this->redirect(Router::url(array('controller' => 'admin', 'action' => 'dashboard')));
重定向正确完成,但由于某种原因,重定向到的 URL 未正确构建。URL 采用以下结构(请注意 URL 中的双 [root] 部分 - 这是错误的):
http://localhost/[root]/[root]/admin/dashboard
当然,由于此控制器/操作不存在,因此会显示错误。URL 应脱离此形式:
http://localhost/[root]/admin/dashboard
我似乎找不到确切的问题是什么,因为 cakePHP 不是我的核心甜点,有没有人可以指出我正确的方向?
谢谢!
$this->redirect("YOUR URL");
example $this->redirect('/admins/dashboard');
这样您就可以轻松重定向!
您可以在 Router::url 中使用 'full_base' 参数。例如
$url = Router::url( array(
'controller' => 'posts',
'action' => 'view',
'id' => $post[id],
'full' => true
) );
这将为您提供一个完整的基本网址。当我在本地主机的子目录中运行 CakePHP 时,我发现了这个固定的路由问题。
你可以这样简单地正确
$this->redirect(array('controller' => 'admins', 'action' => 'dashboard'));
你可以简单地纠正这一点
Router::connect('/', array('controller' => 'users', 'action' => 'index'));