Ask the experts, a tp5 multi-condition filtering routing problem
小理飞刀
小理飞刀 2020-05-03 11:44:59
0
11
1165

A multi-condition filtering question type: type, the parameters are 1, 2, 3, etc. Region: city, the parameters are 12, 22, 44, 44, etc. Price: cate, the parameters are 1, 2, 3, 4. The current URL address is: http://localhost/school/type/1/city/12/cate/1/. How can I reduce this URL address to this: http://localhost/school/1-12- 1/, that is, hiding parameter names such as type, city, and cate. This problem may lead to the following two problems: 1. If the URL entered by the user is: http://localhost/school/1-1, because the parameters passed are all IDs, that is, the order of the parameters is disrupted, how to ensure the result? normal. 2. If the URL entered by the user is: http://localhost/school/1, that is, no other parameters are selected, how to ensure that the result is normal. Thank you so much

小理飞刀
小理飞刀

reply all(4)
至尊宝

Shouldn’t POST be used for optional parameters?

唯you爱

First of all, these two problems are basically not a problem. They can be solved by url routing control, so there will be no confusion. Just implement the default value in the null parameter code. qq895163012

凉官灰

You can use routing in TP5

/school/:type-:city-:cate

or

/school/:id

and then use explode() to separate the id

in the controller
  • reply 1. If the URL entered by the user is: http://localhost/school/1-1, because the parameters passed are all IDs, that is, the order of the parameters is disrupted, how to ensure that the result is normal. 2. If the URL entered by the user is: http://localhost/school/1, that is, no other parameters are selected, how to ensure that the result is normal. Thank you so much
    小理飞刀 author 2020-05-04 10:09:21
  • reply What is the normal result?
    Guanhui author 2020-05-04 13:11:30
  • reply If it is http://localhost/school/1-1, the first one is the type parameter and the second one is the city parameter. Just give the default value to the cate parameter.
    Guanhui author 2020-05-04 13:14:39
  • reply The style of http://localhost/school/1-1-0 is implemented. I want to make the parameters optional. If only type is selected, it is this http://localhost/school/1. For city, http://localhost/school/23, for type and city, http://localhost/school/1-23, if you select all 3, it will look like this: http://localhost/school/1-23 -1
    小理飞刀 author 2020-05-04 13:43:00
  • reply Thank you very much for your answer!
    小理飞刀 author 2020-05-04 13:47:23
  • reply The method you mentioned won't work.
    Guanhui author 2020-05-04 15:56:02
  • reply Got it Thanks
    小理飞刀 author 2020-05-04 18:46:29
小理飞刀

Top up

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!