php 싱글톤(singleton) 패턴인데 클래스 외부에서 function을 선언함으로 해당 클래스 자체에서 사용 가능하게 되는 형태였네요. CI가 이런 형태로 구현되어 있습니다.

<?php

function &#038; get_instance()
{
 return controller::get_instance();
}

class controller {
 private static $instance;

 function __construct(){
  self::$instance = &#038; $this;
  $this->load = new loader();
 }


 public static function &get_instance(){
  return self::$instance;
 }
}

class loader{
 function model($model_name){
  $controller = & get_instance();
  $controller->$model_name = new $model_name;
 }
}

class say{
 function hello(){
  echo "hello";
 }
}

class main extends controller {
   function __construct(){
      parent::__construct();
      $this->load->model("say");
   }

   function index(){
    $this->say->hello();
   }
}

$c = new main();
$c->index();

웹사이트 설정

웹페이지 색상을 선택하세요