I am trying to load a Codeigniter model from another application. I know this can be done easily with HMVC but using that technique means all modules should be in the same /application
directory, as far as I am aware.
The folder structure I have is similar to this:
document_root
- my_app/
- application/
- controllers/
- models/
- application/
- controllers/
- models/
I have a model in /my_app/application/models/
that I want to load from a controller in /application/controllers
. Is it possible to go about doing this?
This is a bit tricky. I found another answer on SO with the possible solution:
Your best bet is to use symlinks if you can and link them into a sub-directory of your models directory. This would be simple and clean.
Barring that, you should extend Loader and overwrite the &model method to look in the secondary directory (perhaps reassign $path to the alternate application's model folder if $path == 'frontend').
If that also isn't an option, loading is done through APPPATH.'models/'.$path . '/' .$model.EXT. This means you can access the model by the relative path to APPPATH.'models/'. Don't do that if you can possibly avoid it, however. It is non-obvious and an invitation to errors.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.