Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Load current module config
  • Hi,

    I'm trying to use Fuel Modules.

    I've created my module and created my first controller. In this one, I want to use Auth package. In the config module file, I've added "auth" package in the "always_load" section. But It seems that the config file is not loaded. I've the error "Class 'Auth' not found". And if I add "auth" in the "always_load" section in the main app config file, it works. So, I think that's because my module config is not loaded.

    Here's my controller :

    namespace MyModule;

    use \Controller_Hybrid, \Input, \Config, \Lang, \Auth, \Asset, \Theme, \Fuel, \Response;

    class Controller_Authentication extends Controller_Hybrid
    {
        public $theme = "mymodule";

        public function before()
        {
            if (Input::is_ajax())
            {
                return parent::before();
            }

            //Config
            Config::load('MyModule::config', true);
            //Lang
            Lang::load('main.yml');
        }

        public function action_logout()
        {
            $auth = Auth::instance();
            $auth->dont_remember_me();
            $auth->logout();
            Session::set_flash('success', Lang::get('admin.authentication.logout'));
            Response::redirect('admin');
        }

        public function after($response)
        {
            // If no response object was returned by the action,
            if (empty($response) or  ! $response instanceof Response)
            {
                // render the defined template
                $response = Response::forge($this->theme->render());
            }
     
            return parent::after($response);
        }
    }
  • You don't need to manually load the config file, packages are self-contained, if they need config, they will load it.

    Auth does need to be in the "always_load" packages section though. If not, the package isn't known to the autoloader, which will then be unable to load any classes from it.

Howdy, Stranger!

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

In this Discussion