Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Need help with HMVC example
  • Hello,
    In my welcome controller I have
     $widget = Request::forge('admin/test/index', true)->execute();
    echo $widget;

    in folder modules, I have a folder named admin.
    in admin I have a folder called controllers
    In controllers I have a file named test.php
    in test.php I have:

    namespace test;

    class Controller_test
    {
        public function action_index()
        {
         die('s');
        }

    in my config.php I have:
    'module_paths' => array(
            APPPATH.'modules'.DS,        // path to application modules
            APPPATH.'..'.DS.'globalmods'.DS    // path to our global modules
        ),

    when I start my app at http://localhost/fuel/
     I get


    Uh Oh! We can't find that!




    The controller generating this page is found at APPPATH/classes/controller/welcome.php.


    This view is located at APPPATH/views/welcome/404.php.




  • HarroHarro
    Accepted Answer
    You are missing a folder: And you've got a folder name wrong.

    > in folder modules, I have a folder named admin.
    > in admin I have a folder called controllers

    You need ./modules/admin/classes/controller

    So the folder structure in a module is identical to the structure in fuel/app.
  • Thanks Harro,

    I will give this a try.

     Regards,

    Frank
  • Getting an error.
    Error - Class Admin\Controller_Test does not have a constructor, so you cannot pass any constructor arguments in /Library/WebServer/Documents/fuel/fuel/core/classes/request.php on line 401

    namespace Admin;

    class Controller_Test 
    {

        public function action_index()
        {
            if( ! Request::is_hmvc())
            {
                return "HELLO";
            }
            else
            {
                // this is a HMVC request
            }
        }

    }
  • It's a controller, it needs to extend one of the base controllers:

    class Controller_Test extends \Controller
    {
    }
  • Thank you, I had tried this without the \
    It is working now as long as I remove the Request::is_hmvc()
    It cannot find this.
  • HarroHarro
    Accepted Answer
    You need the backslash because your controller is now in the Admin namespace, and you need to load the "Controller" class from the global namespace.

    Same is true for all other core classes, you need to prefix them with a backslash, otherwise they can not be found. So use: \Request::is_hmvc().

    Please read up on the use of PHP namespaces, it would make this a lot clearer.
  • Thanks Harro, for your patience, this is all new to me coming from CI.
  • No problem, I'm here to help. ;-)

Howdy, Stranger!

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

In this Discussion