In the video tutorials here I can see that MY_Model.php
is placed in the core directory of my CI application just like MY_Controller.php
would be.
My issue is that CI does not load models from the core directory. I have stepped through CI and found that CI is only checking the application\models
folder for models, not the core
folder (found on line 279 of CI 2.1.0 Loader.php file). This makes it so I cannot access MY_Model
directly using $this->load->model('MY_Model')
, though I can extend it just fine.
This makes me wonder why we are putting MY_Model.php
in the core
folder. Any model that is in application\models
can be extended AND accessed directly, so why not put MY_Model.php
there?
The reason for making MY_Model.php
is extending Core model. Its not supposed to load using this->load->model('MY_Model')
. Its already autoloaded. The aim of MY_model
is making common method, properties for all model inside application/models
without hacking the Core files. And if you have extended Core Model, you should write your application models with extending MY_Model
not the CI_Model
.
core\MY_Model.php
were autoloaded then I wouldn't have make all of my other models extend it because its functions would already be available - ubiquibacon 2012-04-04 19:58