Welcome Guest, Not a member yet? Register   Sign In
Single model per aplication .

(This post was last modified: 06-25-2020, 04:41 PM by tony.a.)

Is there any drawbacks in using a single model extending basemodel per aplication ,?
class Basic_Model extends CI_MODEL {

private static $instance;

    function __construct() {
        // Call the Model constructor
    public static function getInstance()
        if (!self::$instance instanceof self) {
            self::$instance = new self;

        return self::$instance;


PHP Code:
Class myModel{
$model // base model
public function __construct() {

$this->model getModelInstance() ; // basic_model singleton


find($params = array())  {


(This post was last modified: 06-25-2020, 06:19 PM by dave friend.)

You don't need the code you show. Any model loaded using $this->load->model(...) already creates a singleton.
You can use the Auto-loading Resources feature to make the model available all the time for the application.

BTW, you do not need the call to parent::__construct(); in Basic_Model because CI_Model does not have a constructor to call.

Theme © iAndrew 2016 - Forum software by © MyBB