dqiu
dqiu

Reputation: 337

Implementing class inheritance in codeigniter

I am confused, again, about implementing OOP in CodeIgniter.

By design, I have two classes, namely Customer and Supplier. Both classes extends a super class I call Institution.

It was not a problem for me when I wrote them using only php (without framework).

class Customer extends Institution {
    public function __construct() {
        parent::__construct();
    }
}

class Supplier extends Institution {
    public function __construct() {
        parent::__construct();
    }
}

class Institution extends DBConnection {
    public function __construct() {
        parent::__construct();
    }
}

class DBConnection {
    // do CRUD activities here
}

The questions are:

  1. How do I write them using CI?
  2. Is it as Controller or in Model the best way to implement them? What factors should be considered?

A friend suggested a way I thought a bit hacky, model extends model. I try, if possible, to do it in codeigniter-appropriate way.

Any suggestion will be appreciated.

Upvotes: 0

Views: 1253

Answers (1)

J0HN
J0HN

Reputation: 26921

Well, as it is going to be your domain model entities, it should be models. And there is nothing wrong in having another model class as a base class for model class. So, you'll just need to make your Institution (or DBConnection if you prefer to keep it) class extend CI_Model.

Upvotes: 1

Related Questions