Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Autoload a module?
  • Hi, is there a way to autoload a module once I call it?

    I have a Model_User (orm) relationships, and it seems that it throws me an error because the relationships models come from other modules and as I didn't load them previously it throws me an error of course ... so, what I should do?



  • HarroHarro
    Accepted Answer
    No.

    You can not call anything in the module until the autoloader knows the modules' namespace, and knows where it is on disk. So you need to use either Module::load() first, or define the module in the always_load section of your config.

    Having said that, creating tight dependencies between modules is a bad idea, the idea behind modules is that they are optional, and can be replaced or removed. If you need "helper" style stuff, you better create packages for it.
  • The thing is that I'm working alone on a project, and since I discovered the modules of FuelPHP everything is a lot easier to me, easier to debug, to test, the config files views and everything in the same folder, and so on.

    So for example I have a module named "users" and another one named "articles", and as they have relationships in the database I have to call from users with $has_many the articles model.


    What would you suggest me my friend? I wouldn't believe that I'm the only one that does it this way, or am I?


    Thank you for your previous reply.
  • HarroHarro
    Accepted Answer
    In general, if your "seperated code" contains frontend code, i.e. a controller, create a module. If it doesn't, create a package.

    However, both need to be loaded before they can be used, which you can do in the always_load section of your app config.

    Packages have the added benefit of a bootstrap, so you can use that to have one package load others, to define the classes in the package to speed up the autoloader, etc.

    Modules are URI routeable, so be careful if they contain controllers, since they can be called from the client.

    I'd say if depedencies are not a problem for you, just define them in your always_load section of the config.
  • It could be longer but not clearer!

    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