Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Using module classes outside the module
  • I am trying to use this: \Mymodule\Myclass::mymethod('params'); I have the module autoloading in the config. When I run Module::loaded('account'); it returns that the module is loaded.
    I can also use the url: http://devsite.com/account/auth and get the response that is expected in the browser. So I know that the module is working. But when I try to use any of module's classes outside of the module I get the following error: ErrorException [ Error ]: Class 'Account\Auth' not found Any ideas?
  • Nope, clueless. If the url works, then the autoloader knows how to load the class. \Account\Auth::method should work fine.
  • Can you get that functionallity to work locally for any of your development? Would this be a server envrionment issue? I have it running locally in a mamp pro setup.
  • Yup, no problem. I do it all the time. Every module I create has a class called 'Module' in modules/module-name/classes, which is called by the base controller to fetch menu items, check rights, get authorisations, etc. Stuff like this:
      foreach (\Config::get('module_paths') as $m)
      {
       // loop through all modules installed in this path
       $modules = \File::read_dir($m, 1, array('!.*' => 'file'));
    
       foreach ($modules as $module => $unused)
       {
        // trim the trailing slash
        $module = rtrim($module, DS);
    
        // make sure the module is loaded
        \Module::load($module);
    
        // fetch the menu items defined by this module and accessible by the user
        $this->menu_items = array_merge($this->menu_items, call_user_func('\\'.ucfirst($module).'\\Module::menu'));
       }
      }
    

Howdy, Stranger!

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

In this Discussion