Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Use module inside a package
  • Is there a way to use a module inside a package whichs maps the url?
    For example:

    packages/mypackage/modules/mymodule/classes/controllers/mycontroller

    should be reachable over the url /mymodule/mycontroller?

    What do I have to do for that? I have added the package to allways_load already.
  • HarroHarro
    Accepted Answer
    For a module to be found, it's root folder needs to be configured in "module_paths".

    You can do that in your package bootstrap. Assumping your modules are in a folder called 'modules' in your package, add this to the bootstrap:

    $mp = \Config::get('module_paths', array());
    $mp[] = __DIR__.DS.'modules';
    \Config::set('module_paths', $mp);

    Optionally followed by

    \Module::load('yourpackagemodule');

    if you want to autoload your module too.
  • Thank you! For me, I had to add:

    $mp[] = __DIR__.DS.'modules' . DS;
  • Ah, yes. Sorry about that.
  • And how does it work with Controller classes?

    At the moment I have the following:

    app/classes/controller/myctrl.php
    class Controller_Myctrl extends \Custom\Controller_RestAuthenticated
    app/classes/custom/controller/restauthenticated.php
    namespace Custom;
    abstract class Controller_RestAuthenticated extends Controller_Rest
    And it works. But now I want to move the Controller_RestAuthenticated to the package as well.

    I have added to the package bootstrap:
    Autoloader::add_namespace('Mypackage', __DIR__.'/classes/');
    Autoloader::add_core_namespace('Mypackage');
    And moved the class to
    packages/mypackage/classes/custom/controller/restauthenticated.php
    But he can't find the class.
  • Don't use add_core_namespace(), you need the namespace to find the controllers.
  • And what is "custom"? You can't just change the folder layout in the "classes" folder...

Howdy, Stranger!

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

In this Discussion