private static $instance;
    private $data;    public static function & instance()
    {
        if (!isset(self::$instance))
        {
            $class = __CLASS__;
            self::$instance = new $class;
        }
        return self::$instance;
    }    public function __construct()
    {
        $domain = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ?
                $_SERVER['HTTP_X_FORWARDED_HOST'] :
                (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '');        $this->_load($domain);
    }    public function _load($domain)
    {
        $cache = Mycache::instance();
        $key = $domain;
        if(!($this->data = $cache->get($key)))
        {
            $this->data = DB::select()->from('sites')->where('domain','=',$domain)->execute()->current();            if($this->data)
            {
                $cache->set($key,$this->data);
            }
            else
            {
                //TODO not find the domain,trigger the error
                echo 'no domain data';
                exit;
                //$this->request->status = 404;
                //$this->request->redirect('system_error');
            }
        }
    }    /**
     *
     * get config data
     * @return  Array
     */
    public function get($key = NULL)
    {
        if(empty($key))
        {
            return $this->data;
        }
        else
        {
            return isset($this->data[$key])?$this->data[$key]:'';
        }
    }

解决方案 »

  1.   

    怎么解释,虽然语言是相通的,但也要从基础看起吧。php中的函数,php类的继承,php的框架…………
      

  2.   

    怎么转行了,当初想做JAVA,没找到工作
      

  3.   


      private static $instance;
      private $data;
      //单例
      public static function & instance()
      {
      if (!isset(self::$instance))
      {
      $class = __CLASS__;
      self::$instance = new $class;
      }
      return self::$instance;
      }
    //构造函数,根据访问的域名地址加载网站配置。
      public function __construct()
      {
      $domain = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ?
      $_SERVER['HTTP_X_FORWARDED_HOST'] :
      (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '');  $this->_load($domain);
      }
      //加载网站配置
      public function _load($domain)
      {
      $cache = Mycache::instance();
      $key = $domain;
      //如果未命中缓存,则从数据库读取配置,并写入缓存。
      if(!($this->data = $cache->get($key)))
      {
      $this->data = DB::select()->from('sites')->where('domain','=',$domain)->execute()->current();  if($this->data)
      {
      $cache->set($key,$this->data);
      }
      else //没有从数据库取到配置,提示错误信息。
      {
      //TODO not find the domain,trigger the error
      echo 'no domain data';
      exit;
      //$this->request->status = 404;
      //$this->request->redirect('system_error');
      }
      }
      }  /**
      *
      * get config data 获取配置信息,不指定$key的情况返回所有配置。
      * @return Array
      */
      public function get($key = NULL)
      {
      if(empty($key))
      {
      return $this->data;
      }
      else
      {
      return isset($this->data[$key])?$this->data[$key]:'';
      }
      }
      

  4.   

    你这代码和框架没关系吧 学过java的话翻翻php的书 不可能完全理解不了上面的代码
      

  5.   

    我和你相反我是php转java,一起努力
      

  6.   

    kohana3不错啊,很多地方都借鉴了zend framework,特别是类命名方式,改进了不少