Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Is there a routing solution for this?
  • In a few of my controllers I have the config do some routing. For example the users controller, usually you would view a user like 'users/view/1' to see user #1, I dont like having the action 'view' in all of the urls so I routed it like this
    'users/(:segment)' => 'users/view/$1'
    

    This works fine, but then if I have a method defined like
    public function action_list($page){
    //do something
    }
    

    if there isn't a page specified in the URL ie users/list it will get routed to 'users/view/' which I don't want. Is there a way to set up the routing config to say like if there is a single integer after /users/ then go to /users/view/ otherwise ignore.
  • It's run through preg_replace, thus this should work as long as your ids are numeric:
    'users/([0-9]+)' => 'users/view/$1'
    
  • Jelmer Schreuder wrote on Thursday 1st of September 2011:
    It's run through preg_replace, thus this should work as long as your ids are numeric:
    'users/([0-9]+)' => 'users/view/$1'
    

    Actually I jumped the gun there, this is routing to the correct method but its not passing the integer id.
  • This should work fine:
    'users/(:num)' => 'users/view/$1'
    'users' => 'users/list'
    

    I don't think the first rule will match if there is no numeric parameter present.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion