CakePHP 管理员和网站路由器
CakePHP admin and website router
我正在学习 CakePHP 并且正在构建 CMS,但我似乎无法正确设置我的路由器。
每个 url 都应该使用 WebsiteController 的索引操作,除了 "admin"
/admin 工作,但是当我去 /foobar 时它要求 FoobarController
Router::connect("/admin/:controller/:action",
array("controller" => "admin")
);
Router::connect("/",
array("controller" => "website", "action" => "index")
);
Router::connect("/:slug/*",
array("controller" => "website", "action" => "index"),
array("pass" => array("slug"), "slug" => '(?!admin)')
);
我认为问题出在"slug" => '(?!admin)'
。无论如何你都不需要它,因为以 /admin 开头的 url 已经被你的第一条路线捕获。
其他问题,下面的路由没有意义:
Router::connect("/admin/:controller/:action",
array("controller" => "admin")
);`
它基本上告诉我们通过 admin Controller 和 foobar Controller 来处理 /admin/foobar url。
试试这个:
Router::connect("/admin",
array("controller" => "admin", "action" => "index")
);
Router::connect("/admin/:action",
array("controller" => "admin")
);
Router::connect("/",
array("controller" => "website", "action" => "index")
);
Router::connect("/:slug/*",
array("controller" => "website", "action" => "index"),
array("pass" => array("slug"))
);
所以,我想通了。
删除:
Router::connect("/admin/:action",
array("controller" => "admin")
);
Router::connect("/",
array("controller" => "website", "action" => "index")
);
并添加:
Router::connect("/admin",
array("controller" => "admin", "action" => "index")
);
Router::connect("/:slug",
array("controller" => "website", "action" => "index"),
array("pass" => array("slug"))
);
特别感谢PGBI
我正在学习 CakePHP 并且正在构建 CMS,但我似乎无法正确设置我的路由器。
每个 url 都应该使用 WebsiteController 的索引操作,除了 "admin"
/admin 工作,但是当我去 /foobar 时它要求 FoobarController
Router::connect("/admin/:controller/:action",
array("controller" => "admin")
);
Router::connect("/",
array("controller" => "website", "action" => "index")
);
Router::connect("/:slug/*",
array("controller" => "website", "action" => "index"),
array("pass" => array("slug"), "slug" => '(?!admin)')
);
我认为问题出在"slug" => '(?!admin)'
。无论如何你都不需要它,因为以 /admin 开头的 url 已经被你的第一条路线捕获。
其他问题,下面的路由没有意义:
Router::connect("/admin/:controller/:action",
array("controller" => "admin")
);`
它基本上告诉我们通过 admin Controller 和 foobar Controller 来处理 /admin/foobar url。
试试这个:
Router::connect("/admin",
array("controller" => "admin", "action" => "index")
);
Router::connect("/admin/:action",
array("controller" => "admin")
);
Router::connect("/",
array("controller" => "website", "action" => "index")
);
Router::connect("/:slug/*",
array("controller" => "website", "action" => "index"),
array("pass" => array("slug"))
);
所以,我想通了。
删除:
Router::connect("/admin/:action",
array("controller" => "admin")
);
Router::connect("/",
array("controller" => "website", "action" => "index")
);
并添加:
Router::connect("/admin",
array("controller" => "admin", "action" => "index")
);
Router::connect("/:slug",
array("controller" => "website", "action" => "index"),
array("pass" => array("slug"))
);
特别感谢PGBI