Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Can modules routes be reverted?
  • Hi guys!

    I made a module and it was activated(loaded). In modules/mymodule/config/routes.php I have a couple array routes. However, I just can't reverse URLs from module. 
    So I do not know if reverse module routes is supportes from Fuel. Can modules routes be reverted?
    The global routes config (app/config/routes) is ok.


    Thanks in advance!

    Kazumi
  • What do you mean by "reverse"? Can you give an example?
  • Yes, I do!
    With "reverse route" I mean resolve/convert named routes (like in Python Django Framework) to URLs as here:
    http://fuelphp.com/docs/general/routing.html#/named_routes

    In my app/config/routes.php I can do this:

    return array(
    ...
    'home' => array('home/index', 'name' => 'home_page'),
    ....
    )
    It works well: echo Router::get('home_page')

    But if I have a module routes config as such fuel/app/modules/dashboard/config/routes.php:

    return array(
    ...
    'dashboard/login/check' =--> array('dashboard/login/check', 'name' => 'login_check'),
    ....
    )

    So Router::get("login_check") always returns NULL.

    May be a bug or modules cannot support named routes?


    Thanks!
  • That only works inside the module, when the module is loaded.

    Modules are designed to be loosly coupled, if you have a view in module A that needs a link to a controller in module B, you violate that design, since you tightly integrate A and B (A will no longer work without B).

    So Router::get("login_check") will work, but only from controllers in the "dashboard" module.

    If you insist, you can make a bit of startup code that loops over all modules, loads their routes.php, and adds them to the Router.
  • "So Router::get("login_check") will work, but only from controllers in the "dashboard" module."

    Well... It is exactly what I have.
    'dashboard/login/check' => array('dashboard/login/check', 'name' => 'login_check') maps to controller inside dashboard module. I just can't undestand how it not work.

    Anyway, I'll put all routes in global routes config.


    Thanks, Harro!
  • It's about in which controller you use Router::get(). That you can only do in controllers in the dashboard module.

    In other words, Router::get() can only find global routes, or routes in the current module.

    You can not do Router::get("login_check") in an App controller, or in a controller in another module than "dashboard". If you want that, you need to load module routes manually.

Howdy, Stranger!

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

In this Discussion