Welcome Guest, Not a member yet? Register   Sign In
How exactly CI instantiates Model and Controller?
#2

[eluser]PhilTem[/eluser]
To answer your particular question: CI instantiates them for every request, since PHP has no persistence i.e. every object that you will instantiate will be grabbed by the garbage collector after all data was submitted to the client's computer. That said, every request to any of your pages is "new" to CI/your server and it runs through all lines of necessary code.

The general instantiation of models is pretty straight forward as in procedural/non-framework PHP.

As for example loading a model goes like this (taken from ./system/core/Loader.php)

Code:
[...]
if ( ! class_exists('CI_Model'))
{
load_class('Model', 'core');
}

require_once($mod_path.'models/'.$path.$model.'.php');

$model = ucfirst($model);
$CI->$name = new $model();
$this->_ci_models[] = $name;
return;


Messages In This Thread
How exactly CI instantiates Model and Controller? - by El Forum - 10-02-2012, 09:23 AM
How exactly CI instantiates Model and Controller? - by El Forum - 10-02-2012, 10:59 AM
How exactly CI instantiates Model and Controller? - by El Forum - 10-02-2012, 11:50 AM



Theme © iAndrew 2016 - Forum software by © MyBB