Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Load module config file automatically when route into module
  • First, I know that it can auto load module config file in the main config file.
    But I want the config file only load when I route to the module. e.g.
    1) the module config file won't load if I show the home page.
    -- http://www.mysite.com/home #config for module "Blog" is not loaded. 2) the module config file won't load if I show the home page.
    -- http://www.mysite.com/blog/home/list #config for module "Blog" is loaded. It's there any way that I don't need to write Config::load("Blog::config") in every controller file? Sorry for bad English.
  • Create a base controller for all controllers in the Blog module:
    <?php
    
    namespace Blog;
    
    class Controller_Base extends \Controller
    {
        public function _init()
        {
            // load your config here
            \Config::load('config');
    
            parent::_init();
        }
    }
    
    And then your controllers:
    <?php
    
    namespace Blog;
    
    class Controller_Blog extends Controller_Base
    {
        public function action_index()
        {
            // load your thing here
        }
    }
    
  • OK, thanks. Where should I put this Controller_Base file?
    How to auto load this controller using autoloader? Note: Everything is inside a Module.
  • I have the base controllers in app/classes/controller (as they are global to my apps). If it's called Controller_Base, it should be in a file called base.php. Note that if you use this in modules, know that Controller_Base lives in the global namespace, so you need to use
    <?php
    
    namespace mymodule;
    
    class Controller_Mine extends \Controller_Base
    {
    }
    

    so prefix it with a backslash to load it from global. See the Fuel Depot project on github (http://github.com/fuel/depot) for an example of base controllers...

Howdy, Stranger!

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

In this Discussion