我正在尝试使我的CodeIgniter应用程序与WordPress类似.
我希望能够创建这些URL:
http://www.example.com/my-post-example
http://www.example.com/new-headline-here
http://www.example.com/i-love-stackoverflow
我的路由:
$route['(:any)'] = "core/index/$1";
Run Code Online (Sandbox Code Playgroud)
这将调用我的核心控制器并将页面名称传递给索引函数.
然后我在我的数据库中查找页面名称并将页面显示给用户.到现在为止还挺好.
但是,有时候我想调用另一个控制器.例如:
http://www.example.com/admin/edit_page/3
http://www.example.com/admin/settings
现在我假设我的路线将抓住所有这些规则并将它们发送到我的核心控制器.有没有办法对某些页面进行例外处理?或者在我的Core控制器中进行此检查是个好主意.
例如,
if ($page not in DB) {
// Call controller/method
}
Run Code Online (Sandbox Code Playgroud)
这似乎有点多余,因为我只想让CodeIgniter来处理这个问题.