ѡ̳

标题: thinkphp公共函数之M函数 [打印本页]

作者: admin    时间: 2017-11-12 18:52
标题: thinkphp公共函数之M函数
源码
  1. /**
  2. * 实例化一个没有模型文件的Model
  3. * @param string $name Model名称 支持指定基础模型 例如 MongoModel:User
  4. * @param string $tablePrefix 表前缀
  5. * @param mixed $connection 数据库连接信息
  6. * @return Think\Model
  7. */
  8. function M($name='', $tablePrefix='',$connection='') {
  9.     static $_model  = array();
  10.     if(strpos($name,':')) {
  11.         list($class,$name)    =  explode(':',$name);
  12.     }else{
  13.         $class      =   'Think\\Model';
  14.     }
  15.     $guid           =   (is_array($connection)?implode('',$connection):$connection).$tablePrefix . $name . '_' . $class;
  16.     if (!isset($_model[$guid]))
  17.         $_model[$guid] = new $class($name,$tablePrefix,$connection);
  18.     return $_model[$guid];
  19. }
复制代码







欢迎光临 ѡ̳ (http://www.sunminxuan.cn/bbs/) Powered by Discuz! X3.4