backported loading of models in subdirectory by array Fixed issue bcit-ci#2638 which prevented loading models in sub-folders by passing an array.
dont change class filenames to Ucfirst in CI2 * allow to load `Upercase` and `lowercase` * related to commit 20292311636837e120d205e470e41826820feb46
Add a defensive check in CI_Loader::_ci_load() * Prevents possible internal variable overwrites when loading views * backported from commit 92d1cc05362998ceabe39c4023f41fd939c1f5b2
... | ... | @@ -256,12 +256,17 @@ |
256 | 256 | // Load the local application controller
|
257 | 257 | // Note: The Router class automatically validates the controller path using the router->_validate_request().
|
258 | 258 | // If this include fails it means that the default controller in the Routes.php file is not resolving to something valid.
|
259 | - if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php'))
|
|
259 | + $class = $RTR->fetch_class();
|
|
260 | + if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$class.'.php'))
|
|
260 | 261 | {
|
261 | - show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
|
|
262 | + $class = ucfirst($RTR->fetch_class());
|
|
263 | + if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$class.'.php'))
|
|
264 | + {
|
|
265 | + show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
|
|
266 | + }
|
|
262 | 267 | }
|
263 | 268 | |
264 | - include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php');
|
|
269 | + include(APPPATH.'controllers/'.$RTR->fetch_directory().$class.'.php');
|
|
265 | 270 | |
266 | 271 | // Set a mark point for benchmarking
|
267 | 272 | $BM->mark('loading_time:_base_classes_end');
|
... | ... | @@ -275,7 +280,6 @@ |
275 | 280 | * loader class can be called via the URI, nor can
|
276 | 281 | * controller functions that begin with an underscore
|
277 | 282 | */
|
278 | - $class = $RTR->fetch_class();
|
|
279 | 283 | $method = $RTR->fetch_method();
|
280 | 284 | |
281 | 285 | if ( ! class_exists($class)
|
... | ... | @@ -286,15 +290,16 @@ |
286 | 290 | if ( ! empty($RTR->routes['404_override']))
|
287 | 291 | {
|
288 | 292 | $x = explode('/', $RTR->routes['404_override']);
|
289 | - $class = $x[0];
|
|
293 | + $class = ucfirst($x[0]);
|
|
290 | 294 | $method = (isset($x[1]) ? $x[1] : 'index');
|
291 | - if ( ! class_exists($class))
|
|
295 | + if ( ! class_exists(ucfirst($class)))
|
|
292 | 296 | {
|
293 | 297 | if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
|
294 | 298 | {
|
295 | - show_404("{$class}/{$method}");
|
|
299 | + $class = strtolower($class);
|
|
300 | + if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
|
|
301 | + show_404("{$class}/{$method}");
|
|
296 | 302 | }
|
297 | - |
|
298 | 303 | include_once(APPPATH.'controllers/'.$class.'.php');
|
299 | 304 | }
|
300 | 305 | }
|
... | ... | @@ -319,7 +324,8 @@ |
319 | 324 | // Mark a start point so we can benchmark the controller
|
320 | 325 | $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
|
321 | 326 | |
322 | - $CI = new $class();
|
|
327 | + $classnm = ucfirst($class);
|
|
328 | + $CI = new $classnm();
|
|
323 | 329 | |
324 | 330 | /*
|
325 | 331 | * ------------------------------------------------------
|
... | ... | @@ -348,18 +354,21 @@ |
348 | 354 | if ( ! empty($RTR->routes['404_override']))
|
349 | 355 | {
|
350 | 356 | $x = explode('/', $RTR->routes['404_override']);
|
351 | - $class = $x[0];
|
|
357 | + $class = ucfirst($x[0]);
|
|
352 | 358 | $method = (isset($x[1]) ? $x[1] : 'index');
|
353 | 359 | if ( ! class_exists($class))
|
354 | 360 | {
|
355 | 361 | if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
|
356 | 362 | {
|
357 | - show_404("{$class}/{$method}");
|
|
363 | + $class = strtolower($class);
|
|
364 | + if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
|
|
365 | + show_404("{$class}/{$method}");
|
|
358 | 366 | }
|
359 | 367 | |
360 | 368 | include_once(APPPATH.'controllers/'.$class.'.php');
|
361 | 369 | unset($CI);
|
362 | - $CI = new $class();
|
|
370 | + $classnm = ucfirst($class);
|
|
371 | + $CI = new $classnm();
|
|
363 | 372 | }
|
364 | 373 | }
|
365 | 374 | else
|
... | ... | @@ -241,7 +241,7 @@ class CI_Loader { |
241 | 241 | {
|
242 | 242 | foreach ($model as $babe)
|
243 | 243 | {
|
244 | - $this->model($babe);
|
|
244 | + is_int($key) ? $this->model($value, '', $db_conn) : $this->model($key, $value, $db_conn);
|
|
245 | 245 | }
|
246 | 246 | return;
|
247 | 247 | }
|
... | ... | @@ -255,7 +255,7 @@ class CI_Loader { |
255 | 255 | $path = substr($model, 0, $last_slash + 1);
|
256 | 256 | |
257 | 257 | // And the model name behind it
|
258 | - $model = substr($model, $last_slash + 1);
|
|
258 | + $model = substr($model, $last_slash);
|
|
259 | 259 | }
|
260 | 260 | |
261 | 261 | if (empty(trim($name)))
|
... | ... | @@ -277,18 +277,16 @@ class CI_Loader { |
277 | 277 | foreach ($this->_ci_model_paths as $mod_path)
|
278 | 278 | {
|
279 | 279 | if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
|
280 | - {
|
|
281 | - continue;
|
|
282 | - }
|
|
283 | - if ( ! file_exists($mod_path.'models/'.$path.strtolower($model).'.php'))
|
|
284 | 280 | {
|
285 | 281 | $model = strtolower($model);
|
286 | - continue;
|
|
287 | - }
|
|
288 | - elseif ( ! file_exists($mod_path.'models/'.$path.ucfirst($model).'.php'))
|
|
289 | - {
|
|
290 | - $model = ucfirst($model);
|
|
291 | - continue;
|
|
282 | + if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
|
|
283 | + {
|
|
284 | + $model = ucfirst($model);
|
|
285 | + if ( ! file_exists($mod_path.'models/'.$path.ucfirst($model).'.php'))
|
|
286 | + {
|
|
287 | + continue;
|
|
288 | + }
|
|
289 | + }
|
|
292 | 290 | }
|
293 | 291 | |
294 | 292 | if ($db_conn !== FALSE AND ! class_exists('CI_DB'))
|
... | ... | @@ -309,10 +307,8 @@ class CI_Loader { |
309 | 307 | require_once($mod_path.'models/'.$path.$model.'.php');
|
310 | 308 | |
311 | 309 | $model = ucfirst($model);
|
312 | - |
|
313 | 310 | $CI->$name = new $model();
|
314 | - |
|
315 | - $this->_ci_models[] = $name;
|
|
311 | + $this->_ci_models[] = strtolower($name);
|
|
316 | 312 | return;
|
317 | 313 | }
|
318 | 314 | |
... | ... | @@ -812,6 +808,13 @@ class CI_Loader { |
812 | 808 | */
|
813 | 809 | if (is_array($_ci_vars))
|
814 | 810 | {
|
811 | + foreach (array_keys($_ci_vars) as $key)
|
|
812 | + {
|
|
813 | + if (strncmp($key, '_ci_', 4) === 0)
|
|
814 | + {
|
|
815 | + unset($_ci_vars[$key]);
|
|
816 | + }
|
|
817 | + }
|
|
815 | 818 | $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
|
816 | 819 | }
|
817 | 820 | extract($this->_ci_cached_vars);
|
... | ... | @@ -263,7 +263,7 @@ class CI_Router { |
263 | 263 | */
|
264 | 264 | function _validate_request($segments)
|
265 | 265 | {
|
266 | - if (count($segments) == 0)
|
|
266 | + if (count($segments) === 0)
|
|
267 | 267 | {
|
268 | 268 | return $segments;
|
269 | 269 | }
|
... | ... | @@ -273,6 +273,11 @@ class CI_Router { |
273 | 273 | {
|
274 | 274 | return $segments;
|
275 | 275 | }
|
276 | + elseif (file_exists(APPPATH.'controllers/'.ucfirst($segments[0]).'.php'))
|
|
277 | + {
|
|
278 | + $segments[0] = ucfirst($segments[0]);
|
|
279 | + return $segments;
|
|
280 | + }
|
|
276 | 281 | |
277 | 282 | // Is the controller in a sub-folder?
|
278 | 283 | if (is_dir(APPPATH.'controllers/'.$segments[0]))
|
... | ... | @@ -284,6 +289,9 @@ class CI_Router { |
284 | 289 | if (count($segments) > 0)
|
285 | 290 | {
|
286 | 291 | // Does the requested controller exist in the sub-folder?
|
292 | + if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php'))
|
|
293 | + $segments[0] = ucfirst($segments[0]);
|
|
294 | + |
|
287 | 295 | if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php'))
|
288 | 296 | {
|
289 | 297 | if ( ! empty($this->routes['404_override']))
|
—
View it on GitLab.
You're receiving this email because of your account on gitlab.com. Manage all notifications · Help