Codeigniter load model in library -



Codeigniter load model in library -

i using codeigniter 2.1.3

i trying load model library. code in build in library looks this

$this->ci=& get_instance(); $this->ci->load->database('default')

then in 1 of library methods

when tried line below doesnt work

$this->load->model('model_name')

but when tried this

$this->ci->load->model('model_name','',true)

it works, can explain instance of ci refers , 2 parameters when loading model? in advance.

a library not part of way codeigniter works.

it homemade library, solve task want done in ci application.

this means if want utilize of ci's helpers, models or other libraries, need through ci instance. achieved doing this:

public function __construct() { $this->ci =& get_instance(); }

by assigning instance librarys fellow member named ci, ci related helpers, models , libraries can loaded through $this->ci. trying $this referring current library - not ci instance.

to load model correctly, in library, $this->ci->load->model('model_name'); enough. sec parameter allows access model through different object name. 3rd parameter not necessary loading models, allows autoload database driver.

if want access model through same member:

$respone = $this->ci->model_name->method();

codeigniter

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -