Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Loading Modules and Namespaces
  • Im trying to figure out loading a module I want to develop. Here in my confide, I am loading a module:
     'modules'  => array('pinups'),
     'module_paths' => array(
      APPPATH.'modules'.DS
     )
    

    I have a home controller loading at Controller_Home which for now is just seeing whats happening.
    class Controller_Home extends Controller {
     
     public function action_index() {
      echo __NAMESPACE__.'<br>';
      $view = View::forge('home');
      $view->myvar = 'test';
      $loaded = Module::loaded();
      print_r($loaded);
      echo Pinups\Home::index();
    
      return $view;
    
     }
     
    }
    

    The above when going to my_site.com/home results in an error but before the error, an array is printed:
    [pinups] => /srv/www/themoviepostersite.com/dev/fuel/app/modules/pinups/
    Fatal error: Class 'Pinups\Home' not found in /srv/www/themoviepostersite.com/dev/fuel/app/classes/controller/home.php on line 17
    
    

    Which shows me my module is getting loaded. My module uses the structure outlined in the documentation.
    So in my Pinups module home controller:
    namespace Pinups
    
    class Controller_Home {
     
     public function action_index() {
      echo 'hello pinup';
      
     }
     
    }
    

    So my obvious question, is how should I load a module?
    I also tried making my module the default page in the router config resulting in a 404.
    Pinups\Home::index()
    

    Any help in the right direction here is appreciated.
    Rich
  • Try this:
    namespace Pinups
    
    Class Controller_Pinups extends \Controller
    {
     
    public function action_index() 
    {
      $str = 'hello pinup'; 
      echo $str;
     
      return $str;
    }
     
    }
    

    http://fuel.Johns-Jokes.com/
  • So I still get an error:
    ErrorException [ Error ]: Class 'Pinups\Home' not found
    APPPATH/classes/controller/home.php @ line 17
    

    Should I import the namespace in my Home Controller?
    Or try to make the Pinups\Home my default route? I am loading a Module Controller within my standard controller both which are extending the Core Controller, which doesn't seem right.
    So in my Main Controller, the line:
    echo Pinups\Home::index();
    
    is generating the error. Any ideas of what I am doing wrong?
  • Try adding a a backslash to View like this: $view = \View::forge('home'); If you put the "home" view under a subfolder in the views of your module then add that also: $view = \View::forge('subfolder/home');
  • Thanks grasshopper,
    Its not an issue with the View though this will help me when I get there. It's calling the module in general.
    Fuel is not finding the class at Pinups\Home when I call it.
    Is there something I am missing in the setup or should I make the module the default route?
    I am not sure why the "ErrorException [ Error ]: Class 'Pinups\Home' not found" error is occurring. Any help here would be great.
    Thanks
    Rich
  • The same applies to 'Pinups\Home', which should be '\Pinups\Home'. If you want to route to a module, by default the URI is "/module/controller/method/any_params".
  • Harro Verton wrote on Wednesday 4th of July 2012:
    The same applies to 'Pinups\Home', which should be '\Pinups\Home'. If you want to route to a module, by default the URI is "/module/controller/method/any_params".
    I have just updated a Module Pinup on two servers along with the source code: http://fuel.johns-jokes.com/John_Pinups http://test-002.anetizer.com/John_Pinups @Harro Verton I did notice that the Uri:class is showing incorrectly on Johns-Jokes.com Both applications use the same Fuel source but the App source is duplicated.
  • You have a base configured? If not it will use the info from $_SERVER, I can't imagine code that would come up with a different hostname by itself...
  • Harro Verton wrote on Wednesday 4th of July 2012:
    You have a base configured? If not it will use the info from $_SERVER, I can't imagine code that would come up with a different hostname by itself...

    Yes you were right... I checked my config file and had base_url configured. When "Reset to null" the base is automatically detected. Many thanks, Fuel is getting a little better every day.
  • It worked for me :) I can see my basic module on "/module/controller" URI
    Thx

Howdy, Stranger!

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

In this Discussion