Cml\Model::getInstance PHP Method

getInstance() public static method

初始化一个Model实例
public static getInstance ( ) : Model
return Model | \Cml\Db\MySql\Pdo | \Cml\Db\MongoDB\MongoDB | \Cml\Db\Base
    public static function getInstance()
    {
        static $mInstance = [];
        $class = get_called_class();
        if (!isset($mInstance[$class])) {
            $mInstance[$class] = new $class();
        }
        return $mInstance[$class];
    }

Usage Example

Example #1
0
 /**
  * 定义析构函数 自动释放获得的锁
  */
 public function __destruct()
 {
     foreach (self::$lockCache as $key => $islock) {
         if ($islock) {
             Model::getInstance()->cache($this->userCache)->getInstance()->delete($key);
             unset(self::$lockCache[$key]);
         }
     }
 }
All Usage Examples Of Cml\Model::getInstance