Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Modules and Routing
  • Been playing around with modules, and can't quite seem to figure them out. Let's take a module named Clients in
    app/modules/clients/
    
    with a controller 'Controller_Clients' in
    app/modules/clients/classes/controller/clients.php
    

    Without specifying the module in config.php, the uri '/clients' loads the 'action_index' method of the Clients controller. That's exactly what I expected.
    Now, if I specify in config.php to explicitly load the 'clients' module, that uri brings up a 404. Strange. So the module needs some more controllers. I add
    clients/classes/controller/test.php
    

    Running the URI 'clients/test' doesn't bring up the test controller. Seems fuel is looking inside the Clients controller for the 'test' method. But if you rename the clients controller to something else or delete it, 'clients/test' works fine, but of course now the URI '/clients' brings up a 404.
    Also, now you can add the 'clients' module reference in config.php without it 404ing. Am I doing something wrong or are these still outstanding bugs?
  • I'll have a look...
  • Module routing has been fixed in the develop branch. There's still one issue on the table that I haven't solved yet (and I don't know if it's needed): If you have an application controller of the same name as a module, the router will always load the application controller. That means that if you request /part1/part2, and the part1 controller doesn't have a method called 'part2', you'll get a 404. Even if your part1 module has a controller called 'part2'. I don't think that can't be fixed, you'll only detect this issue when you'll be rerouted to the 404 handler due to the missing method...
  • Thanks for fixing that so quickly! I think it would be a good idea to change that functionality to prefer the module rather than the application controller: For example, if an application has a controller that you want to change the functionality of, you could essentially "drop in" a new controller as a module instead of having to change/replace the application controller. I haven't thought it out too thoroughly, so maybe there are better ways of doing it, but I think it'd be great to be able to extend apps that way.
  • Yeah, we've been discussing this in IRC. Unfortunately, due the way Fuel locates files at the moment it's very difficult to alter the search order. I've created an issue about this in the bugtracker.
  • After downloading the latest version by modules does not work, it was working fine with earlier version. this is what i have: config.php
    'module_paths' => array(APPPATH.'modules'.DS), modules
    --registration
    classes
    model
    controller
    registration.php
    views
    index.php modules/registration/classes/controller/registration.php
    <?php
    namespace Registration; 
    Class Controller_Registration extends \Controller_Template 
    &#123; 
        public function action_index() 
        &#123;
        $this->template->content = \View::factory('index');
        }
    }
    

    What has changed to stop it working?
  • What doesn't work? Error messages? Your controller works without problems here, providing there's a template called 'template' that can be found (as you didn't set one in your controller).
  • Am getting 404 error, yes I do have template called template which is the default.
  • Ok, found an issue, module detection was broken. I just committed the fix. Can you update your Fuel install and check again?
  • Ok, will try again. Thanks for looking into this.

Howdy, Stranger!

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

In this Discussion