Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Router name with 1.9/dev
  • Hey,
    I updated to 1.9/dev but My router return empty route when I call from name.

    I load my user module routes : \Config::load('user::routes', 'routes');
    Look at config for logout :
    user/logout (Array, 2 elements)
             0 (String): "user/user/logout" (16 characters)
             name (String): "logout" (6 characters)

    but I got empty route when I do : echo \Router::get('logout')

    in user module config : my routes.php is :
    return array(
    'user/login' => array('user/user/login', 'name' => 'login'),
    'user/logout' => array('user/user/logout', 'name' => 'logout'),
    );

    whats happened it work fine from 1.8
    thanks
  • HarroHarro
    Accepted Answer
    Very good question, I never use it, so I haven't noticed it. I'll have a look.
  • HarroHarro
    Accepted Answer
    I can't reproduce it, works fine here.

    Is the module loaded? If not, the route config isn't parsed.
  • I tested in a new fuel app (1.8 and 1.9/dev) it doesn't work.

    created a module user with a routes file in config : 
    return array('user/logout'  => array('user/user/logout', 'name' => 'logout'),)

    I setup in config app file to setup load module :
    'module_paths' => array(
    APPPATH.'modules'.DS
    ),
    'modules'  => array('user'),

    and in app/welcom app controler I wrote :
    Config::load('user::routes', 'routes');
    echo 'route hello : '. Router::get('hello');
    echo 'route login : '. Router::get('logout');

    I can't have route for login.

    Its strange because in my blog app with 1.8 it's working. Moving on 1.9 it break the feature.

    you are right the route config isn't parsed but it still in routes config. How I can debug that ?
  • In my case the module is loaded, so It should be parsed. It stored in routes config but not in static::$routes from Router core class.
  • HarroHarro
    Accepted Answer
    Weird, since I did exactly the same. And I get a fully qualified URL back to /user/login and /user/logout.

    edit: 

    ah, wait, you load the route in a controller OUTSIDE the module... I can reproduce that.
  • yeah in the fuel exemple, and in my app I load from extending Module class :
  • Looking in the code, module routes are only loaded on a request to that module, so module specific routes are only available when a controller in that module has been called.

    I don't see any changes in this code between 1.8 and 1.9/dev, so for the moment I'm clueless.
  • Ah... Next time let me know, saves me quite a bit of time.
  • \Config::load($module.'::routes', 'routes') returns false. Looking further.
  • HarroHarro
    Accepted Answer
    Found it. You are appearantly not on the lastest 1.8.


    This moves loading the routes to before calling always_load, which means that only loading the module route config is no longer sufficient.

    So you have to update your extension to use

    if ($routes = Config::load($module.'::routes', 'routes'))
    {
        \Router::add($routes);
    }
     
  • Sorry for the confusion.
    You say : routes are loaded when a controller in that module has been called.
    But when I call a route's name from anywhere, how fuel can guess what module and route it is, before config was loaded ?

    I would like just load and store all the modules'name, I dont know anymore now how to do that in fuel. 
  • I try your last comment ...
  • HarroHarro
    Accepted Answer
    This would be better, and you can ditch your extension: https://github.com/fuel/core/commit/4d620bfb3467ea8725836b1161f63f1e54421f2b
  • HarroHarro
    Accepted Answer
    module routes are loaded in Request, when a module controller is called.

    It was never contemplated that you would want to get a route from a module from either a global or an other module controller, as that would create a tight coupling between the two, while the idea of modules is that they are self contained.

    With the new config key you can decide whether or not you want to load module routes when you load a module.
  • Thanks Harro. I go test all that ;)
  • all are working now, route and ORM many_to_many relation. Running on 1.9/dev now. Thanks ;)
    take care

Howdy, Stranger!

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

In this Discussion