doutonghang2761 2011-03-25 13:02
浏览 56
已采纳

Codeigniter URL路由问题

I'd like to know how to accomplish the following using the Codigniter MVC framework:

I want the URLs on my site looking like this:

http://www.example.com/florida/miami/12345-selling-a-new-ipod.html
http://www.example.com/texas/houston/21345-nice-red-car-for-sale.html
http://www.example.com/north-carolina/hickory/92634-giving-away-two-kitties.html

So basically the URI is composed of state / city / article.

I want to cover all cities in the 50 states, but I wouldn't want to write a controller for each state and each city.

So my question basically is:

How can I write a single controller that will display a state index based on the first URI segment and a second controller displaying a city index based on the second URI segment?

Best regards

Tom

  • 写回答

2条回答 默认 最新

  • dpbfb7119 2011-03-25 13:56
    关注

    you could do it by configuring a route in your config/routes.php

    $route['^(:any)/(:any)'] = "some_controller/some_method/$1/$2";
    

    which will map everything into the some_method function of your some_controller class. so if you have anything else which isn't example.com/state/city it will also get sent there.. you would have to route it out of there with another route.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?