GithubHelp home page GithubHelp logo

Comments (3)

 avatar commented on June 10, 2024 1

It's better to make two route path for that... So the values are consistent. example :
`Route::add('/user/([0-9]*)',function($id){
var_dump($id);
},'get');

Route::add('/user/([0-9])/edit/([a-z])',function($id,$name){
var_dump($id,$name);
},'get');`

If you try : domain.com/user/14/edit/daniel it will try to match against the first route:add and then go to the second one.

from simplephprouter.

elymatos avatar elymatos commented on June 10, 2024 1

Thanks for answers!
My use case is like 'module/controller/action/id' where action can be optional (in this case, 'main') and 'id' is optional too.
I've tried with '?' but it doesn't work as expected, because the '/' must be optional too.
Then for while I prefer to define three routes and to be sure about the parameters.
Thanks for sharing!

from simplephprouter.

steampixel avatar steampixel commented on June 10, 2024

Hey,

currently I have no time to test this idea but try something like this:

Route::add('/user/([0-9]*)/edit/([a-z]*)?',function($id, $optional){
  echo 'Edit user with id '.$id.'<br/>';
  echo 'The optional parameter is '.$optional.'<br/>';
},'get');

Noticed the question mark in the regexp? This should make the second parameter optional. But I have not tested this. Please try this and report back the results please.

from simplephprouter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.