Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
HMVC between different app
  • I'm having this architecture



    public_1 (vhost 1)
    public_2 (vhost 2)

    And I'm trying to access app_1 controllers using hmvc request from a app_2 controller.
    The idea is to fetch results from app_1 without duplicating the models and the controllers logic.
  • HarroHarro
    Accepted Answer
    Assuming app_1 is under public_1 and app_2 under public_2, you can't. They are seperate apps, they don't share the same application environment.

    If you want to interact between two apps, you need to create an API, and use Request_Curl() to call the API from the other app.
  • I guess you can use module for your needs if your project is just started.

  • Modules and Packages allow you to share code, but as I understood, the question was about accessing data?
  • app 1 has been developed years ago, and has been under continuous development since; the app is only intranet accessible.

    app 2 will use some of the controllers & data of app 1 and will be wide-web accessible.

    So the idea is to reuse the code & models of app 1: 
      - without duplicating the code
      - with no direct access to models ( hmvc requests ? ), so even with an access to app 2 files it would be impossible to fetch data which should not be accessible ( ie: Model_MyModel::find('all') ).

    I've also considered the modules (globals) solution but this will bring a lot of changes on app 1.
  • To re-use or share:
    - frontend code, use a module
    - backend code, use a package

    Moving clases is not that complex. 

    Say your app1 has a model in ./app/classes/model/admin/users.php, called Model_Admin_Users, in the global namespace. You can copy this to ./app/modules/admin/classes/model/users.php, which will then be the class \Admin\Model_Users. 

    Then change the original to: class Model_Admin_Users extends \Admin\Model_Users;

    And your app1 would continue to function like normal, providing you gave autoloaded the Admin module.

    There is never direct access possible to Models, only Controllers can be requested.

    If you want controlled data access (something your second bullet suggests), the only way to solve that is to create an API (for example a REST api, with authtentication) in app1, and have app2 talk to that to request the data. There is no other option.

Howdy, Stranger!

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

In this Discussion