Model in subfolder with same name as model in main folder |
I noticed that if there is a model in a subfolder with the same name as model in the main folder, it is ignored in favor of the model in the main folder.
How to reproduce: Download and install CodeIgniter 3.1.2 /application/models/Blog_model.php: PHP Code: class Blog_model extends CI_Model { /application/models/legacy/Blog_model.php: PHP Code: class Blog_model extends CI_Model { /application/controllers/Welcome.php: PHP Code: class Welcome extends CI_Controller { Result: the main blog_model gets called twice: Quote:Hello from the main Blog_model! Aliasing the main one like this doesn't help: PHP Code: $this->load->model('blog_model','main_blog_model'); Oddly enough, if I comment out the lines for the main blog model, THEN the blog model in the subdirectory gets called: PHP Code: // $this->load->model('blog_model'); Quote:Hello from the legacy Blog_model! My planned workaround is to rename the models in the subdirectory, eg. /models/legacy/blog_model becomes /models/legacy/legacy_blog_model but at that point I might as well move it up to /models. (admittedly, that might have been the best way all along; no need to alias anything.) Is this a genuine issue or am I making a mistake?
CodeIgniter maintains its own list of loaded components, so it doesn't try to load the legacy/Blog_model, even though it locates it.
You need models, controllers and libraries (all classes) to be uniquely named. (01-06-2017, 10:19 AM)ciadmin Wrote: CodeIgniter maintains its own list of loaded components, so it doesn't try to load the legacy/Blog_model, even though it locates it. Thank you for replying so quickly and providing clarification. Now I understand what is really going on.
Code-igniter maintains its own list of loaded components. But for you can make another folder for access blog_model
$this->load->model('admin/blog_model'); $this->load->model('legacy/blog_model','legacy_blog_model'); If you are use this structure than its working fine. |
Welcome Guest, Not a member yet? Register Sign In |