在代码编写器中如何使用URL忽略控制器的默认行为


How to use the URL ignoring controller's default behavior in codeigniter?

我有一个CI代码库在我的本地主机,其URL是http://localhost/mydomain/site/

这里"site"是文件夹不是控制器

我有DB表数据字段,其中某些区域的位置存储。

理想情况下,当上面的URL被点击时,默认的home控制器被调用。

但是我想如果用户点击URL为http://localhost/mydomain/site/southtown/,其中"southtown"是位置名称,用户可以在视图页面中看到所有与southtown相关的数据。

注:数据来自于数据库中的位置(这里是southtown)。

也会有url作为

localhost/mydomain/网站/southtown aboutus

localhost/mydomain/网站/southtown/灵感

localhost/mydomain/网站/southtown/服务

这些将是各自的页面,根据URL中指定的位置,所有数据来自DB

尝试使用路由,如

$route["home"] = "home";
$route["home/(:any)"] = "home/index/$1";

和在您的home控制器,做:

public function index($location = "") {
   //get $location and check against db
}

因此,当使用点击url http://localhost/mydomain/site/southtown/时,您的$location将具有值"southtown"。