search

Home  >  Q&A  >  body text

Ask the experts, a tp5 multi-condition filtering routing problem

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

小理飞刀小理飞刀1724 days ago1236

reply all(11)I'll reply

  • 至尊宝

    至尊宝2020-05-08 15:10:41

    Shouldn’t POST be used for optional parameters?

    reply
    0
  • 唯you爱

    唯you爱2020-05-05 00:40:21

    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

    reply
    0
  • Guanhui

    Guanhui2020-05-04 10:06:35

    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
    0
  • 小理飞刀

    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

    小理飞刀 · 2020-05-04 10:09:21
    Guanhui

    What is the normal result?

    Guanhui · 2020-05-04 13:11:30
    Guanhui

    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 · 2020-05-04 13:14:39
    小理飞刀

    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

    小理飞刀 · 2020-05-04 13:43:00
    小理飞刀

    Thank you very much for your answer!

    小理飞刀 · 2020-05-04 13:47:23
    Guanhui

    The method you mentioned won't work.

    Guanhui · 2020-05-04 15:56:02
    小理飞刀

    Got it Thanks

    小理飞刀 · 2020-05-04 18:46:29
  • 小理飞刀

    小理飞刀2020-05-03 20:12:52

    Top up

    reply
    0
  • Cancelreply