Welcome Guest, Not a member yet? Register   Sign In
Pass argument to model constructor while loading a model
#2

*Alternatively* Here is another option, I feel as though the above is complicated when it can be something more simple.

/system/core/Loader.php

PHP Code:
public function model($model$name ''$db_conn FALSE)


replace with

PHP Code:
public function model($model$name ''$db_conn FALSE$params = array())


then where the model is being loaded,

PHP Code:
$CI->$name = new $model(); 

replace with
PHP Code:
if (isset($params) && !empty($params)) {
 
 $CI->$name = new $model($params);
}
else {
 
 $CI->$name = new $model();

Reply


Messages In This Thread
RE: pass argument to model constructor while loading a model - by idealcastle - 01-13-2015, 10:12 AM



Theme © iAndrew 2016 - Forum software by © MyBB