• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Single model per aplication .

#1
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

#2
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.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.