Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
About config files in modules
  • Hi;

    I've a module called "adminblog", with a config file called "blog.php".

    Well, if i load a config file from the module i get the contents of /fuel/app/modules/adminblog/config/blog.php.

    But if I load a config file from the /fuel/app/classes/controllers/controllerXX.php i get the contents of /fuel/app/config/blog.php.

    How can i get always the contents of /fuel/app/config/blog.php merged with /fuel/app/modules/adminblog/config/blog.php??

    The code with i get the config is:
                \Config::load('blog','blog');
                $cfgBlog = \Config::get('blog');

    Thanks!
  • Ideally you don't.

    Modules are designed to be individual application components, and nothing outside the module should have a need to access anything in it, which would create tight coupling, a bad design practice.

    If you need to access the module, the preferred way is to use an HMVC call. So have your app controller call a module controller, and have that return the module's blog config. Ideally through a route, so you can alter the route if you later decide to design a new blog module. Your HMVC call should also be in a try/catch block, to capture an HttpNotFoundException when you are ever in a situation where you will not have a blog module installed.

    If you don't care about all that, you can prefix the config name with the namespace to load a config file explicitly from that namespace. In this case that would be

    $cfgBlog = \Config::load('adminblog::blog', 'blog');

    As always, Fuel gives you the choice.

Howdy, Stranger!

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

In this Discussion