|
楼主 |
发表于 2009-2-20 18:37:04
|
显示全部楼层
本帖最后由 塑料做的铁钉 于 2009-2-20 19:04 编辑
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?
---------------------------------------------------------------------------------------
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:
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;
}
}
解决方案放上来分享 |
|