Welcome Guest, Not a member yet? Register   Sign In
Mutli Application Calling Model From Shared Site In Single Installation Codeigniter 4
#1

How to call models from other multi application site in single installation codeigniter 4 ?
https://stackoverflow.com/q/74457092/6786634
Please help. Could someone help answer my question above ?
Is that possible to call or access model from another site in multi application in single installation ?
I keep getting class not found even the path is correct.
I have ask a clear question in the above link. Please see.

Thank You
Reply
#2

See, it might help you.
https://github.com/kenjis/codeigniter4-m...pps-sample
Reply
#3

(11-16-2022, 09:39 AM)datamweb Wrote: See, it might help you.
https://github.com/kenjis/codeigniter4-m...pps-sample

I already done the setup. But the problem is I want the secondary site use the main site models. In the link above it is just a setup and didn't show how to call the model from the main site from the secondary site.
Reply
#4

(This post was last modified: 11-16-2022, 09:40 PM by iRedds.)

To do what you want, your model must have a namespace other than the default one.
By default, models have the \App\Models namespace.

PHP Code:
// You need to add namespace in application 1 and application 2 configs
'Source\Models' => 'path/to/app/Models/'

// change class to
namespace Source\Models;
classSettings { }

// And in both applications call 
= new \Source\Models\Settings(). 

In general, it is better to move the model into a separate module, which can be connected in both applications.
Reply
#5

(11-16-2022, 09:38 PM)iRedds Wrote: To do what you want, your model must have a namespace other than the default one.
By default, models have the \App\Models namespace.

PHP Code:
// You need to add namespace in application 1 and application 2 configs
'Source\Models' => 'path/to/app/Models/'

// change class to
namespace Source\Models;
classSettings { }

// And in both applications call 
= new \Source\Models\Settings(). 

In general, it is better to move the model into a separate module, which can be connected in both applications.

Thank You @iRedds. I update the answer in the https://stackoverflow.com/q/74457092/6786634
I have separate the module. I created a shared/Models folder. So the shared model can be access from both application 1 and 2. 
Now everything is working.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB