0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

forgot to comeback after reading your answer. it makes more sense to me with them as models rather than controller. so i took your suggestion and constructed them all as ones.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.