如何组织国家/州/城市浏览在codeigniter url [英] How to organize country/state/city browsing in codeigniter url

查看:111
本文介绍了如何组织国家/州/城市浏览在codeigniter url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个包含国家/州/城市浏览界面的网站。
对于SEO,我想在URL中包含国家/州/城市的名称。
例如,网址可能包含其他变量,如下所示:

I'm creating a website that includes a country/state/city browsing interface. For SEO purposes, I want to include the name of the country/state/city in the URL. For example, the URL may include additional variables and would be something like:

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类。

I need to fit this functionality into CodeIgniter. I'm not sure how to organize the major components, specifically the Controller, and possibly the Library class.

是否有标准或最佳做法?

Is there a standard or best practice approach?

推荐答案

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

Edit the routes.php file located in your config folder.

正如Bora的链接=http://ellislab.com/codeigniter/user-guide/general/routing.html =nofollow> CI URI路由)文档中的一些示例:

As noted in the link from Bora (CI URI Routing) Some examples from the documentation:

$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段中为每个国家设置一个路由。这可能更容易做到:

In your case you need to reconcile the names of the functions in your controllers and the desired URL names. You could end up with the examples that you show in your question, but you'd have to lay out a route for every country that you want in the first URI segment after domain.com. It's probably easier to do this:

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

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

And then in your routes folder:

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

如果您需要通过URL向控制器传递其他参数,您可以使用查询字符串,或添加

If you need to pass additional parameters to your controller via URL you can use query strings as you show above, or add

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

这篇关于如何组织国家/州/城市浏览在codeigniter url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆