git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5645 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-09-16 01:24:34 +00:00
parent 078dbba8c8
commit 1b64111871

View file

@ -47,13 +47,16 @@
}'); }');
} }
/** /**
* Loads all models. * Loads all models, or set of specified models.
* E.g:
*
* loadModels() - Loads all models
* loadModels('User', 'Group') loads models User & Group
*/ */
function loadModels() { function loadModels() {
if (!class_exists('Model')) { if (!class_exists('Model')) {
require LIBS . 'model' . DS . 'model.php'; require LIBS . 'model' . DS . 'model.php';
} }
$path = Configure::getInstance();
if (!class_exists('AppModel')) { if (!class_exists('AppModel')) {
if (file_exists(APP . 'app_model.php')) { if (file_exists(APP . 'app_model.php')) {
require(APP . 'app_model.php'); require(APP . 'app_model.php');
@ -62,17 +65,33 @@
} }
Overloadable::overload('AppModel'); Overloadable::overload('AppModel');
} }
$loadModels = array();
if (func_num_args() > 0) {
$args = func_get_args();
foreach($args as $arg) {
if (is_array($arg)) {
$loadModels = am($loadModels, $arg);
} else {
$loadModels[] = $arg;
}
}
}
$loadedModels = array(); $loadedModels = array();
$path = Configure::getInstance();
foreach ($path->modelPaths as $path) { foreach ($path->modelPaths as $path) {
foreach (listClasses($path) as $model_fn) { foreach (listClasses($path) as $modelFilename) {
list($name) = explode('.', $model_fn); list($name) = explode('.', $modelFilename);
$className = Inflector::camelize($name); $className = Inflector::camelize($name);
$loadedModels[$model_fn] = $model_fn;
if (!class_exists($className)) { if (empty($loadModels) || in_array($className, $loadModels)) {
require($path . $model_fn); $loadedModels[$modelFilename] = $modelFilename;
list($name) = explode('.', $model_fn); }
if (isset($loadedModels[$modelFilename]) && !class_exists($className)) {
require($path . $modelFilename);
list($name) = explode('.', $modelFilename);
Overloadable::overload(Inflector::camelize($name)); Overloadable::overload(Inflector::camelize($name));
} }
} }