Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Module in routed mode
  • May I look at example or step-by-step instruction to do a module in routed mode?

    As I read in docs fuel must automaticaly detect, when first segment match module name. Is it?

    I create the module Admin, create class/controller/admin.php:

    namespace Admin;

    class Controller_Admin extends Controller_Template
    {
      public function action_index() { ...}
    }

    1. What I have to do for invoking index action with request http://localhost/public/admin/admin/index?
    2. What I have to do for invoking index action with request http://localhost/public/admin?
    3. May I set routing for module like 'admin/(:any)' for invoking any actions of Admin class?
    4. May I set routing for module like 'admin/user/(:any)' for invoking any actions of User class (when I create it)?

    Thanks.
  • HarroHarro
    Accepted Answer
    Yes, you are correct.

    The Fuel router will try to match the first segment against a define module, and if a match is found, load it. It will only do that if there was NO route patch though, so with your admin example, if your app routes.php would contain a route starting with 'admin/', that would be matched first.

    As you your questions:

    1.nothing, that would resolve automatically
    2. 'admin' => 'admin/admin/index';  or 'admin' => 'admin/admin'
    3. That would need a route 'admin/(:any)' => 'admin/admin/$1'
    3. That would need a route 'admin/user/(:any)' => 'admin/admin/user/$1'

    Note that route 3 would not be matched by http://localhost/admin, since that route has the trailing slash as required. If you want to have it optional, it needs to be inside the brackets. Same applies for 4.

    Passing index is optional, if no method is detected in the URL (in case of "admin/admin" for example), it will assume you would want to call the index method.
  • Thank you for the answers, but excuse me ;)

    De facto, I need to do nothing for all this four variants. All of this works fine automatically from box. And it's great!

    Only the reason for my questions (I think something not working) is that I did not uncomment this:
    APPPATH.<span class="string">'modules'</span>.DS :)

    I thought that is already done from box :)

    Sorry for my dumb mistakes.
  • All work as I expected! It is super very fine! Thank you :)

Howdy, Stranger!

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

In this Discussion