Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing CodeIgniter Models in Other Models

It used to be that within a CodeIgniter model you couldn't access another model.

$this->load->model('bar'); $this->bar->something(); 

Is this still valid, or have they changed it?

like image 896
Ali Avatar asked May 16 '09 15:05

Ali


People also ask

How do I load a CI 3 model?

Auto-loading Models If you find that you need a particular model globally throughout your application, you can tell CodeIgniter to auto-load it during system initialization. This is done by opening the application/config/autoload. php file and adding the model to the autoload array.

Can we call model from view in CodeIgniter?

First Model interacts withe the database. Then load the model and access relevant function in your controller. Finally load the data to view from the controller. That's it...you can show the data simply in a foreach loop.

How do I load a CI 4 model?

Instead of CI3's $this->load->model(x); , you would now use $this->x = new X(); , following namespaced conventions for your component. Alternatively, you can use the model function: $this->x = model('X') ;.


1 Answers

Those are some VERY long answers for a simple question.

Short answer: This is now fully supported. Cross-load away if you feel like it!

like image 184
Phil Sturgeon Avatar answered Oct 06 '22 01:10

Phil Sturgeon