Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Best place to put models in a package
  • Is there a standard or recommended way to structure classes in packages? For example, if I were to put a model "Foo" into a package, would it be called "Model_Foo" and be placed into packages/mypackage/classes/model/foo.php? Obviously I can put them where I like, and it will work, but if there are recommended patterns to follow that make it easier for people to read, modify and use a package, then I would like to follow that. -- Jason Just to add to this, the documentation here http://docs.fuelphp.com/general/packages.html says to just dump all the classes into one folder.
  • Jason Judge wrote on Wednesday 25th of January 2012:
    Just to add to this, the documentation here http://docs.fuelphp.com/general/packages.html says to just dump all the classes into one folder.
    To start with this one: I don't see that. The fact that the example folder structure doesn't show sub folders doesn't mean you should dump everything in one folder. Use your own judgement.
    Jason Judge wrote on Wednesday 25th of January 2012:
    Is there a standard or recommended way to structure classes in packages?
    No, there isn't. It largely depends on what the package is supposed to do, whether you include third party classes that require a specific folder structure, etc. Again, use your best judgement.
    Jason Judge wrote on Wednesday 25th of January 2012:
    For example, if I were to put a model "Foo" into a package, would it be called "Model_Foo" and be placed into packages/mypackage/classes/model/foo.php?
    As to classes in sub folders, the autoload supports two methods:
    // in both cases assuming packages/mypackage/classes/model/foo.php:
    
    // option 1
    namespace mypackage;
    class Model_Foo {}
    
    // option 2
    namespace mypackage/Model;
    class Foo {}
    

    btw, this works for any class, not only for models. it also works in app and modules.
  • Okay - a good pattern is there for the application, so I'll just follow that for the packages too. Thanks, -- JJ

Howdy, Stranger!

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

In this Discussion