【发布时间】:2018-02-13 20:16:49
【问题描述】:
我有一个非常大的应用程序(许多控制器和模块),在应用程序中有文章(帖子),我想把 URL 像: example.com/[category_name]/[article_name] 即: example.com/gadgets/top-ten-coolest-gadgets-of-2018
我有一个名为 Content 的控制器,因此 URL 设置如下: example.com/content/[category_name]/[article_name]
我想从 URL 中删除 "/content/",所以,首先我尝试在 routes.php 中添加以下内容:
$ route ['(:any)/(:any)'] = '/content/categoryArticles/$1/$2';
但是其余的控制器停止工作,所以我不得不将它们全部添加到 routes.php 中(还有很多)。
我想在 URL 找不到控制器时尝试使用 404_override 作为默认路由并将所有重定向到 /content/categoryArticles 即,这样做:
route ['404_override'] = '/content/categoryArticles/'
并在 categoryArticles 函数中,将 URL 分段分解并确定参数。
这是个好习惯吗?
【问题讨论】:
标签: php codeigniter routing