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

(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 ,?
Code:
class Basic_Model extends CI_MODEL {

private static $instance;

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

        return self::$instance;
    }

}


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

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

}

function 
find($params = array())  {
$this->model->db->from(my_table());...

Reply


Messages In This Thread
Single model per aplication . - by tony.a - 06-25-2020, 04:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB