Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Question about routes. How to retrieve parameter from the url ?
  • Hi,

    I'm trying to retrieve a parameter from the url.
    I tried different things with routes but I'm stuck.

    I did the following in my route file :

    'newRouteName/(:any)'      => 'controllerName/$1'

    On my action_index method I want to be able to get the parameter from the url so I declared it like this :
    public function action_index($param) {echo $param;}
    But this is not working.

    If I remove the parameters, the routing is well working but I need to get the parameter from the url.

    Could someone help me on this please ?
     
    Thank you in advance.

    Philippe
  • HarroHarro
    Accepted Answer
    Any additional parameters are passed to the method, so that should work just fine. Are you sure you don't have a routing issue, because that route doesn't route to 'action_index', it routes to $1.

    If you want to route to index, use

    'newRouteName/(:any)'      => 'controllerName/index/$1'
  • Thank you very much it soled my issue.
    I thought if I did not  mentionned the method name, the default action_index was executed but I was wrong.
    Cheers !
    Philippe
  • HarroHarro
    Accepted Answer
    If there is no second segment, FuelPHP will default to 'index'.

    But if there is a second segment, there is no way of knowing if that is the method name, or the first parameter of index.
  • Thank you very much once again for your help.

Howdy, Stranger!

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

In this Discussion