Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Need a suggestion on a main namespace with all classes
  • Hy guys,
    I would create a set of classes/methods to be provided to other developers ( that create modules ), to controllers ( base ) and to API ( rest controllers ). It can be useful to get that centralized into a single namespace ( like "CMS" for example ), and I simple call a function like :
    \CMS\Pages::get();
    \CMS\Settings::save(...);
    \CMS\Users::delete(...);
    ...
    

    I thought it would be correct using a module with this structure :
    - modules
       - cms
       |- classes
       |  |- [dir] controller ( empty )
       |  |- [dir] model
       |  |- pages.php
       |  |- users.php
       |  |- settings.php
       |- config
       |...
    

    Can you suggest me if using modules is a good idea, or packages are better?
    what confused me is that packages :
    - do not map to the URL,
    - not approachable through HMVC requests
  • Packages are considered as extensions to the core, where as modules are extensions to the application. From a technical point of view, there is no difference if you put this in a module or a package, both are namespaced, and both can be called as you described. There are some gotcha's though that you have to take into account when calling module code. Everything in Fuel works from the context of a request. That includes all file searching. If you call a module, or make a call cross-module, you will have to take this into account. For example, if you want to load a module config file from a class you've called, it will not be found, as the request will have the app as it's context, and is not aware of the module. The loader and request architecture is currently being rewritten, so this logic may change for v1.1.
  • Ok, I think it's clear. Thank you WanWizard!

Howdy, Stranger!

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

In this Discussion