Welcome Guest, Not a member yet? Register   Sign In
how to load a model with a parameter to construct the model....
#1

[eluser]Unknown[/eluser]
how to load a model with a parameter to construct the model....

just like :

class M_model extends Model {


function __construct($user_id = NULL) {
parent::Model ();
//do something here...
}

when i want
$this->load->model('m_model');

how to transfer the parameter $user_id to the model?
#2

[eluser]darkhouse[/eluser]
That would require changing the loader library I believe, as it's the class that would say $this->m_model = new M_model();

But instead of loading it in the constructor, why can't you just setup an init method, like this:

Code:
class M_model extends Model {

   private $user_id = NULL;

   public function __construct() {
      parent::Model ();
      //do something hereā€¦
   }

   public function init($user_id = NULL){
      if($user_id !== NULL) $this->user_id = $user_id;
   }

}
#3

[eluser]Unknown[/eluser]
a good idea thank you !




Theme © iAndrew 2016 - Forum software by © MyBB