Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Best way to retrieve method parameters
  • Is Uri::segment() the recommended way to retrieve controller parameters? If so, are there any suggested "best practices" to make the code a bit more readable than just writing something like Uri::segment(3)?
    On the one hand it's definitely simple and fast. On the other hand it's less clear from the code (especially when there are multiple parameters) than either GET or POST where you identify the parameter by name. Thanks for any suggestions!
  • That's how I'm doing it. I usually set it to a variable and pass it around. ie $id = Uri::segment(3); if(!empty($id)) $this->do_something($id);
  • You can use params: http://fuelphp.com/docs/general/routing.html (heading Advanced Routing). Then you can request for example a user_id variable from the URI this way:
    $this->param('user_id')
    
  • Advanced routing looks neat; the only quibble I might have is the "global" nature of specifying such routes in the config file, but maybe that's a good thing. Anyway it definitely gets me named parameters so I will try that. I assume I should still check if (!empty($this->param(..))) like calvinfroedge suggested... The answers were very helpful. I did RTFM but didn't come across this. I forgot I could google-search the docs, though. I wish there was a "basic questions" area. I'm not just learning FuelPHP but learning framework-based programming along the way, so some dumb questions are inevitable... Thanks to both of you for the help, much appreciated!

Howdy, Stranger!

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

In this Discussion