Skip to content
Advertisement

Mutli Application Calling Model From Shared Site In Single Installation Codeigniter 4

How to call models from other multi application site in single installation codeigniter 4 ?

The folder structure look like this :

JavaScript

This is my example code :

In Site1


Constants.php I have define a root directory to targeted the site2.

JavaScript

This return :

E:Projectwebsitesite2

Autoload.php

I have setup PSR4.

JavaScript

Then I Run SPARK COMMAND :

JavaScript

And return

JavaScript

Then NameSpace SourceModels is Found. So far everything is okay.

Controller => Home.php

JavaScript

When I run the controller I got :

Class “SourceModelsSetting” not found

Next,

In Site2

I have model “Setting” in Site2 Model Folder.

For Note :

Everything In Site 2 Is running properly.

My question is for the error I got “Class “SourceModelsSetting” not found” What is the proper setting to call the site 2 model in single application installation codeigniter 4 ?.

For Note : This is single installation codeigniter 4 for two website. And I shared the system folder.

Advertisement

Answer

I found the problem. This is the correct way to do this.

Folder Structure

JavaScript

Controller – Home.php

JavaScript

Autoload.php

JavaScript

Constants.php

JavaScript

DBSetting.php

namespace sharedModels; use CodeIgniterModel;

class DBSetting extends Model {

JavaScript

}

We can also call the model in site 2. Just set the correct path in Autoload.php to refer to models in site 2.

Note : If the model in site 2 content another model or link, if we call from the site 1 then codeigniter 4 system will read the link, model from site 1. So make sure to call the plain model in site 2. Or just create a share model folder like above.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement