public function __get($var) { if ($var == 'view') { // 传递 全局的 $conf $this->view = new template($this->conf); return $this->view; // 不建议直接在 control 直接操作 DB!!! 留给插件作者应急之用。 // 用法:$this->db->query("SHOW STATUS"); } elseif ($var == 'db') { $conf = $this->conf; $type = $conf['db']['type']; $dbname = "db_{$type}"; return new $dbname($conf['db'][$type]); } else { // 遍历全局的 conf,包含 model $this->{$var} = core::model($this->conf, $var); if (!$this->{$var}) { throw new Exception('Not found model:' . $var); } return $this->{$var}; } }
function requestModels(&$modelsNeeded) { $modelsNeeded = array("article", core::model("blog"), core::model("comments")); }
static function library($name) { static $used= array(); if (isset($used[$name])) return; $used[$name]= true; return core::model($name); }
function __get($var) { if ($var == 'db') { $this->{$var} = $this->get_db_instance(); return $this->{$var}; } elseif ($var == 'cache') { $this->{$var} = $this->get_cache_instance(); return $this->{$var}; } else { // 遍历全局的 conf,包含 model if (!empty($this->old_conf)) { $conf =& $this->old_conf; } else { $conf =& $this->conf; } $this->{$var} = core::model($conf, $var); if (!$this->{$var}) { throw new Exception('Not found model:' . $var); } return $this->{$var}; } }