Skip to content

Commit c844c2e

Browse files
committed
Laoder make is to load any model name in unix
* Unix like OS are CAmelCase so lest permit to load models from CI3 or CI2 no matter if first is uppercase
1 parent 8dcc089 commit c844c2e

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

appsys/core/Loader.php

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,18 @@ public function library($library = '', $params = NULL, $object_name = NULL)
226226
*
227227
* This function lets users load and instantiate models.
228228
*
229-
* @param string the name of the class
230-
* @param string name for the model
231-
* @param bool database connection
232-
* @return void
229+
* @param mixed $model Model name
230+
* @param string $name An optional object name to assign to
231+
* @param bool $db_conn An optional database connection configuration to initialize
232+
* @return object
233233
*/
234234
public function model($model, $name = '', $db_conn = FALSE)
235235
{
236-
if (is_array($model))
236+
if (empty($model))
237+
{
238+
return;
239+
}
240+
elseif (is_array($model))
237241
{
238242
foreach ($model as $babe)
239243
{
@@ -242,11 +246,6 @@ public function model($model, $name = '', $db_conn = FALSE)
242246
return;
243247
}
244248

245-
if ($model == '')
246-
{
247-
return;
248-
}
249-
250249
$path = '';
251250

252251
// Is the model in a sub-folder? If so, parse out the filename and path.
@@ -259,9 +258,9 @@ public function model($model, $name = '', $db_conn = FALSE)
259258
$model = substr($model, $last_slash + 1);
260259
}
261260

262-
if (empty($name))
261+
if (empty(trim($name)))
263262
{
264-
$name = $model;
263+
$name = strtolower($model);
265264
}
266265

267266
if (in_array($name, $this->_ci_models, TRUE))
@@ -275,14 +274,22 @@ public function model($model, $name = '', $db_conn = FALSE)
275274
show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
276275
}
277276

278-
$model = strtolower($model);
279-
280277
foreach ($this->_ci_model_paths as $mod_path)
281278
{
282279
if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
283280
{
284281
continue;
285282
}
283+
if ( ! file_exists($mod_path.'models/'.$path.strtolower($model).'.php'))
284+
{
285+
$model = strtolower($model);
286+
continue;
287+
}
288+
elseif ( ! file_exists($mod_path.'models/'.$path.ucfirst($model).'.php'))
289+
{
290+
$model = ucfirst($model);
291+
continue;
292+
}
286293

287294
if ($db_conn !== FALSE AND ! class_exists('CI_DB'))
288295
{

0 commit comments

Comments
 (0)