@ 2018-03-06T06:43:41Z <?php
// https://github.com/bcit-ci/CodeIgniter/blob/635256265a38e655c00f4415d5f09700f28c5805/system/core/Common.php#L140
function load_class($class) {
return (new $class());
}
// https://github.com/bcit-ci/CodeIgniter/blob/b862664f2ce2d20382b9af5bfa4dd036f5755409/system/core/CodeIgniter.php#L316
function &get_instance() {
return CI_Controller::get_instance();
}
// https://github.com/bcit-ci/CodeIgniter/blob/b862664f2ce2d20382b9af5bfa4dd036f5755409/system/core/Loader.php#L51
class CI_Loader
{
public function model($model, $name = '', $db_conn = FALSE)
{
$class = $model.'Model';
$CI =& get_instance();
$CI->{$model} = new $class;
}
}
// https://github.com/bcit-ci/CodeIgniter/blob/b862664f2ce2d20382b9af5bfa4dd036f5755409/system/core/Controller.php#L52
class CI_Controller {
private static $instance;
/**
* Class constructor
*
* @return void
*/
public function __construct()
{
self::$instance =& $this;
$this->load =& load_class('CI_Loader');
}
/**
* Get the CI singleton
*
* @static
* @return object
*/
public static function &get_instance()
{
return self::$instance;
}
}
// your models
class fooModel {
public $foo;
}
class barModel {
public $bar;
}
// your controller
class Controller extends CI_Controller {
public function indexAction()
{
$this->load->model('foo');
$this->load->model('bar');
}
}
// instance container
$app = (new class{});
$app->controller = new Controller();
// loaded by router
$app->controller->indexAction();
print_r($app);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.2.0 - 8.2.25 , 8.3.0 - 8.3.13 Deprecated: Creation of dynamic property Controller::$load is deprecated in /in/fPCK3 on line 38
Notice: Only variables should be assigned by reference in /in/fPCK3 on line 38
Deprecated: Creation of dynamic property class@anonymous::$controller is deprecated in /in/fPCK3 on line 74
Deprecated: Creation of dynamic property Controller::$foo is deprecated in /in/fPCK3 on line 21
Deprecated: Creation of dynamic property Controller::$bar is deprecated in /in/fPCK3 on line 21
class@anonymous Object
(
[controller] => Controller Object
(
[load] => CI_Loader Object
(
)
[foo] => fooModel Object
(
[foo] =>
)
[bar] => barModel Object
(
[bar] =>
)
)
)
Output for 7.0.0 - 7.0.33 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.34 , 7.3.0 - 7.3.31 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.30 Notice: Only variables should be assigned by reference in /in/fPCK3 on line 38
class@anonymous Object
(
[controller] => Controller Object
(
[load] => CI_Loader Object
(
)
[foo] => fooModel Object
(
[foo] =>
)
[bar] => barModel Object
(
[bar] =>
)
)
)
Output for 7.3.32 - 7.3.33 class@anonymous Object
(
[controller] => Controller Object
(
[load] => CI_Loader Object
(
)
[foo] => fooModel Object
(
[foo] =>
)
[bar] => barModel Object
(
[bar] =>
)
)
)
Output for 5.6.0 - 5.6.40 Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/fPCK3 on line 73
Process exited with code 255 . preferences:dark mode live preview
93.64 ms | 411 KiB | 5 Q