From 1b64111871ac6cb60bc0de0811fc85b897665439 Mon Sep 17 00:00:00 2001 From: phpnut Date: Sun, 16 Sep 2007 01:24:34 +0000 Subject: [PATCH] Closes #1827 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5645 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/basics.php | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/cake/basics.php b/cake/basics.php index 9b6252c6f..da0d6707b 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -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() { if (!class_exists('Model')) { require LIBS . 'model' . DS . 'model.php'; } - $path = Configure::getInstance(); if (!class_exists('AppModel')) { if (file_exists(APP . 'app_model.php')) { require(APP . 'app_model.php'); @@ -62,17 +65,33 @@ } 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(); - + $path = Configure::getInstance(); foreach ($path->modelPaths as $path) { - foreach (listClasses($path) as $model_fn) { - list($name) = explode('.', $model_fn); + foreach (listClasses($path) as $modelFilename) { + list($name) = explode('.', $modelFilename); $className = Inflector::camelize($name); - $loadedModels[$model_fn] = $model_fn; - if (!class_exists($className)) { - require($path . $model_fn); - list($name) = explode('.', $model_fn); + if (empty($loadModels) || in_array($className, $loadModels)) { + $loadedModels[$modelFilename] = $modelFilename; + } + + if (isset($loadedModels[$modelFilename]) && !class_exists($className)) { + require($path . $modelFilename); + list($name) = explode('.', $modelFilename); Overloadable::overload(Inflector::camelize($name)); } } @@ -1608,4 +1627,4 @@ } return $val2; } -?> \ No newline at end of file +?>