【问题标题】:How to organize country/state/city browsing in codeigniter url如何在 codeigniter url 中组织国家/州/城市浏览
【发布时间】:2014-09-09 21:57:50
【问题描述】:

我正在创建一个包含国家/州/城市浏览界面的网站。 出于 SEO 的目的,我想在 URL 中包含国家/州/城市的名称。 例如,URL 可能包含其他变量,类似于:

http://www.domain.com/USA/NewYork?Category=car&color=black&Model=2009&page=5

http://www.domain.com/Spain/Allcity?Category=car&color=black&Model=2009&page=20

我需要将此功能融入 CodeIgniter。我不确定如何组织主要组件,特别是 Controller,可能还有 Library 类。

是否有标准或最佳实践方法?

【问题讨论】:

标签: codeigniter codeigniter-routing


【解决方案1】:

编辑位于您的配置文件夹中的routes.php 文件。

如 Bora (CI URI Routing) 的链接中所述,文档中的一些示例:

$route['journals'] = "blogs";
//A URL containing the word "journals" in the first segment will be remapped to the "blogs" class.

$route['blog/joe'] = "blogs/users/34";
//A URL containing the segments blog/joe will be remapped to the "blogs" class and the "users" method. The ID will be set to "34".

在您的情况下,您需要协调控制器中的函数名称和所需的 URL 名称。您最终可能会得到您在问题中显示的示例,但您必须在 domain.com 之后的第一个 URI 段中为您想要的每个国家/地区布置一条路线。这样做可能更容易:

http://www.domain.com/locations/USA/NewYork?Category=car&color=black&Model=2009&page=5

然后在您的路线文件夹中:

$route['locations/(.*)/(.*)'] = 'locations';

如果您需要通过 URL 将其他参数传递给控制器​​,您可以使用如上所示的查询字符串,或添加

$route['locations/(.*)/(.*)/([0-9]{1,5})'] = 'locations/$1';
//assumes that parameter is numeric, 0-9 up to 5 digits

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-20
    • 2011-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-08
    • 2014-09-08
    • 1970-01-01
    相关资源
    最近更新 更多