Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Basic named route example
  • There is an example of a BASIC named route in APPPATH/config/routes.php.
    i.e.
    /**
     * This is an example of a BASIC named route (used in reverse routing).
     * The translated route MUST come first, and the 'name' element must come
     * after it.
     */
    // 'foo/bar' => array('welcome/foo', 'name' => 'foo'),
    
    Just wondering what the 'name' element is for?
  • Ok, so that clears that up for me. But can I assume that unloaded modules cannot be reverse routed? I can't seem to wrap my head around this part of Fuel...
  • Surely if the module is not loaded then routes don't exist therefore no they can't reverse routed.
  • That's how I understood it, but at some point someone mentioned unloaded modules and I couldn't quite understand it. Now I'm a bit confused.
  • Why would you want to if the module isn't even loaded? Am I missing the point here :)
  • Phil Foulston wrote on Wednesday 27th of July 2011:
    Why would you want to if the module isn't even loaded? Am I missing the point here :)

    Even if the module isn't loaded you can use it as a widget. And build pages with it. Modules don't need to be auto loaded.
  • Hi Dregond, Yeap got that but the module doesn't need to be loaded for this so routes don't come in to it.
  • Reverse routing is something experimental, and afaik not yet complete. The idea behind reverse routing is that you define a mapping between URL and controller/method in your routes. When you want to generate a link in a view, you don't use a hardcoded path, but refer to that controller/method. Based on the route defined the URL will be generated. This allows you to change your routes easily, and all the links in your view will automatically follow.
  • Thanks, WanWizard. Perhaps that explains why changing the value of the 'name' element seems to have no effect.
  • It should be fully functional, I haven't used it yet but I think Dan already is. Though there's some more advanced usages (with regex) that aren't supported yet. The idea of reversed routing is like this: say you got an admin area and you have a route setup for it. You can just link to that specific route using Html::anchor('admin/start/overview', 'Overview') now you move stuff around and end up moving that specific page to 'admin/overview'. Now you need to update all your links...
    When using reverse routing with these name routes you'd create your anchor like this: Html::anchor(Router::get('admin_overview'), 'Overview') and of course you name your route 'admin_overview' in the routing config. Using it like this you can move the goal of the route around without ever having to change all references to that page. This is also why changing the name won't change anything now, because it only affects something you're not (yet?) using.
  • Thanks for the explanation, Jelmer. I can see where that functionality could come in real handy.
    When I get home I'll move some modules around to see how it works?
    Just to be sure I'm thinking right, this does apply to modules as well?
  • Took a quick look through the code, should work for modules as well. I think it only works for active modules though (when your current controller is in the module), loading a module through Fuel::add_module() won't add the routes. I think this should be considered a bug actually... (I'm making an issue for Dan about this on Github)
  • You guys are great. Thanks!
  • This has been fixed. See here: https://github.com/fuel/core/issues/224 When you add a module via Fuel::add_module() the routes are now loaded into the router so reverse routes work as expected.

Howdy, Stranger!

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

In this Discussion