请教高手,一个tp5多条件筛选 路由问题
小理飞刀
小理飞刀 2020-05-03 11:44:59
0
11
1031

一个多条件筛选问题类型:type,参数分别是1,2,3等地区:city,参数分别是12,22,44,44等价格:cate,参数分别是1,2,3,4等现在的URL地址是:http://localhost/school/type/1/city/12/cate/1/请问:如何把这个URL地址缩减成这样:http://localhost/school/1-12-1/,也就是把type,city,cate这样的参数名隐藏。这个问题可能会衍生下面2个问题:1、如果用户输入的URL是:http://localhost/school/1-1,因为参数传的都是ID ,也就是参数顺序打乱了,如何确保结果正常。2、如果用户输入的URL是:http://localhost/school/1,也就是没有选其他的参数,如何确保结果正常。非常感谢

小理飞刀
小理飞刀

membalas semua(4)
至尊宝

可选参不应该用POST方式吗?

唯you爱

首先这两个问题基本上不算问题了,url路由控制就可以解决,所以不会乱,为空null的参数代码里实现默认值就好了。qq895163012

凉官灰

可以使用TP5中的路由

/school/:type-:city-:cate

或者

/school/:id

然后在控制器中用explode()分隔id

  • balas 1、如果用户输入的URL是:http://localhost/school/1-1,因为参数传的都是ID ,也就是参数顺序打乱了,如何确保结果正常。2、如果用户输入的URL是:http://localhost/school/1,也就是没有选其他的参数,如何确保结果正常。非常感谢
    小理飞刀 pengarang 2020-05-04 10:09:21
  • balas 那正常结果是什么
    Guanhui pengarang 2020-05-04 13:11:30
  • balas 如果http://localhost/school/1-1的话第一个是type参数第二个是city参数,cate参数给个默认不就行了
    Guanhui pengarang 2020-05-04 13:14:39
  • balas http://localhost/school/1-1-0这种样式的是实现了,我想做成参数是可选的,只选 type的话,是这种http://localhost/school/1 只选city的话http://localhost/school/23,如果type和city的话http://localhost/school/1-23, 如果3个都选的话,是这样的http://localhost/school/1-23-1
    小理飞刀 pengarang 2020-05-04 13:43:00
  • balas 非常感谢您回答!
    小理飞刀 pengarang 2020-05-04 13:47:23
  • balas 你说的这种方式是行不通的
    Guanhui pengarang 2020-05-04 15:56:02
  • balas 明白 感谢
    小理飞刀 pengarang 2020-05-04 18:46:29
小理飞刀

顶起来

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!