/** * 释放所有对象 * return object|false */ public static function clear($name = '') { self::$_model = (array) self::$_model; if (!empty($name)) { unset(self::$_model[$name]); return true; } foreach (self::$_model as $k => $obj) { unset($obj, self::$_model[$k]); } self::$_model = array(); }
/** * 获取相应MODEL * @param string $name 要实例化的MODEL * @return zbj_components_basemodel|false */ protected function model($name = '') { //默认为主model if (empty($name)) { $name = $this->marter_table; } if (!isset($this->model[$name])) { //检查是否实例化主表 if (!isset($this->model[$this->marter_table])) { //2011.8.10 兼容前个版本写法 $model_class = strpos($this->marter_table, 'model_') === false ? "model_{$this->marter_table}" : $this->marter_table; //2011.8.23 更换为新的模型接口 //$this->model[$this->marter_table] = new $model_class($this->id==0?false:$this->id); $this->model[$this->marter_table] = components_api::get($model_class, $this->id, $this->isLockTable($name) ? false : true); //是否强制读取主库 if ($this->dbentry === true) { $this->model[$this->marter_table]->setDbEntry(); } return $this->model($name); } $relations = $this->model[$this->marter_table]->relations(); if (!isset($relations[$name])) { $this->setError(0, '没有找到表关系' . $name); return false; } //如果是多对一的关系 if ($relations[$name][2] == 'BELONGS_TO') { $id = $this->get($relations[$name][1]); } else { $id = $this->id; } //2011.8.10 兼容前个版本写法 $class_name = strpos($relations[$name][0], 'model_') === false ? 'model_' . $relations[$name][0] : $relations[$name][0]; //2011.8.23 更换为新的模型接口 //$this->model[$name] = new $class_name($id==0?false:$id); if (empty($id)) { $this->model[$name] = components_api::get($class_name); } else { $this->model[$name] = components_api::get($class_name, $id, $this->isLockTable($name) ? false : true); //对于需要实例化数据记录的,不需要保存,直接使用模型接口 //return components_api::get($class_name, $id, $this->isLockTable($name) ? false : true); } } return $this->model[$name]; }