CodeIgniter optional parameter

后端 未结 3 2091
情深已故
情深已故 2021-01-04 13:57

I\'m trying to use routing in CI to create a signup form

signup is re-routed to user/signup

But my signup function can contain a pa

相关标签:
3条回答
  • 2021-01-04 14:19

    The trouble with @Ukuser32's answer is that it allows for URIs like signup69 to be accepted, which in this case might be innocuous but in the general case is undesirable. Just put the slash in with the captured :num

    $route['signup(/:num)?'] = "user/signup$1"
    

    And note that if you have multiple optional segments, then you will need to nest them....

    0 讨论(0)
  • 2021-01-04 14:27

    For anyone else reading this in due course - I believe the answer should be $route['signup/?(:num)?'] which makes the number optional as well. I had similar issues on something else.

    0 讨论(0)
  • 2021-01-04 14:30

    The clearest way to express this would probably be to declare both routes:

    $route['signup'] = "user/signup";
    $route['signup/(:num)'] = "user/signup/$1";
    
    0 讨论(0)
提交回复
热议问题