Sunday, 15 August 2010

php - Codeigniter: how can i tell if a model is already loaded? -



php - Codeigniter: how can i tell if a model is already loaded? -

are there native codeigniter functions can utilize tell if model has been loaded? can php's class_exists() used tell if model has been loaded?

i tempted extend ci_loader core class. (see extending core class)

class my_loader extends ci_loader { function __construct() { parent::__construct(); } /** * returns true if model given name loaded; false otherwise. * * @param string name model * @return bool */ public function is_model_loaded($name) { homecoming in_array($name, $this->_ci_models, true); } }

you checking given model following:

$this->load->is_model_loaded('foobar');

that strategy beingness used ci_loader class.

this solution supports model naming feature of ci, models can have different name model class itself. class_exists solution wouldn't back upwards feature, should work fine if aren't renaming models.

note: if changed subclass_prefix configuration, might not my_ anymore.

php codeigniter class model

No comments:

Post a Comment