Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Using routes config file with Modules
  • I am using fuel/depot on github (https://github.com/fuel/depot) as an example to implement my own admin section of a FuelPHP application. I have it loading the main admin page (dummy.com/admin) however when I try to go to dummy.com/admin/users it doesn't load the users controller. I am using the same structure as is used on the depot application and I have inserted a Debug::dump statement in my default config/routes.php file which it prints to the screen, I have also inserted a dump statement to my modules/admin/config/routes.php file but this is not being returned. I'm assuming this file isn't being loaded, but I am unsure why and how to resolve.
  • The admin structure in Depot is generated by oil (and moved from app to the module), it's standard code, so I wouldn't know what your problem is. What is your definition of "doesn't load"? Does something else load? do you get a 404? If the admin routes.php isn't loaded, that means that the URI request isn't routed to the module at all. So I would look in your app routes for clues.
  • Harro thank you for the quick response. I apologize for not explaining myself very well. If I go to dummy.com/admin it is successfully routing to the action_index inside of my admin module. However, when I go to dummy.com/admin/users it is routing to homepage/404 instead. As I said I have a Debug::dump in both routes.php and what is in app/config/routes.php always displays but what is in modules/admin/config/routes.php doesn't. I have removed it from the code below as it doesn't affect the route itself. Here is my app/config/routes.php:
    <?php
    return array(
     '_root_'  => 'homepage/index',  // The default route
     'about'   => 'homepage/about',
     '_404_'   => 'homepage/404',    // The main 404 route
    );
    

    And this is my modules/admin/config/routes.php:
    <?php
    return array(
     'admin/(:segment)'  => 'admin/admin/$1/index',    // admin module index pages
     'admin/(:segment)/(:num)'  => 'admin/admin/$1/index/$2', // paginated index pages
     'admin/(:any)'  => 'admin/$1',      // all other admin module pages
    );
    

    I didn't realize the admin structure in Depot was generated by Oil. I was hoping to look through the code structure of the Depot github and copy and paste each piece one at a time to help better understand it all. Based on the additional information above, can you think of anything else I may be missing that is causing it to not use my admin routes? If not I will just use oil to generate it and review it that way. I am sure whatever the issue is it is something I am doing or something I have forgotten to copy over.
  • Hi there! I got the same issue in my app. I made a module called "blog" with posts and categories.
    I set up some routes in the file /fuel/app/modules/blog/config/routes.php with a Debug::dump() in it but it never displays. I just wanted that the URI /blog/cat/<category-name> was routed to my module's Blog_Controller::action_category() :
    <?php
    \Debug::dump('blog routes');
    return array(
     'blog/cat/(:any)'  => 'blog/blog/category/$1',
    );
    

    My module's routes.php should be loaded because the module name is part of the URI each time! I don't know why it's never loaded??
  • @cmullinstu, According to those routes, 'admin/users' should be routed to 'admin/admin/users/index'. You have in your admin module a file called 'classes/controller/admin/users.php', containing a class 'Admin_Users' in the namespace 'Admin', which as an 'action_index' method? @bastientanesie, if your module routes aren't loaded, that means the routing engine didn't get that far. Are there no app routes that will catch your 'blog/cat/...' URI? App routes are processed first, only when no match is found it will check if perhaps a module controller is requested. Oh, and it should be Controller_Blog, not Blog_Controller !

Howdy, Stranger!

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

In this Discussion