Search code examples
phpmodulescopeclassloaderphalcon

Phalcon query model from controller in different module


I'm creating a multi module app. It's a big app that I am porting to Phalcon. It has many different sections, so I am creating a module for each of the main ones.

I do not seem to be able to query a model in one module from a controller in another module. In this example I want to list some members on the home page. The home page is in the main module and the users model is in the users module. I'm using namespaces so in the index controller I have for example,

$this->data['members'] = \App\Users\Models\Members::find();

That produces the following error; Fatal error: Class 'App\Users\Models\Members' not found in C:\wamp\www\xyz\app\main\controllers\indexController.php on line 12

I've checked and double checked the namespacing is correct. So how can I interact between modules?


Solution

  • So what you need to do is register the namespace of the other module in the Module.php class (or the bootstrap for global availability) for the module you want to query from! Woo hoo - end of head scratching.