Welcome Guest, Not a member yet? Register   Sign In
How to extend CI_Model?
#1

[eluser]mjijackson[/eluser]
What is the cleanest way to create a custom Model class that extends CI_Model? I tried creating a custom MY_Model file and sticking that in the application/libraries directory, but CI does not instantiate it like it does for other libraries. So then, if I try and load the model library first:

Code:
$this->load->library('model');

I get an error saying that the CI_Model class cannot be found. Any ideas?
#2

[eluser]mjijackson[/eluser]
Problem solved. To extend Model:

Code:
class MY_Model extends Model
{
    
    function MY_Model()
    {
        parent::Model();
    }

}

And in the models:

Code:
require_once APPPATH . '/libraries/MY_Model.php';

class User extends MY_Model {}

Kind of a hack though...
#3

[eluser]thurting[/eluser]
That is how it should be done.

Why do you say that is a hack? There is nothing wrong with using require().
#4

[eluser]mjijackson[/eluser]
It's a hack because there should be a cleaner way to do it within the framework. That's one of the reasons why I use a framework, so it'll take care of the (potentially) messy inclusions for me.




Theme © iAndrew 2016 - Forum software by © MyBB