thinkphp源码讲解——Model.class.php
来源:互联网 发布:golang中defer 编辑:程序博客网 时间:2024/06/07 01:53
M()函数,在thinkphp中主要的作用是实例化模型。源码:
function M($name='', $tablePrefix='',$connection='') { static $_model = array();//定义一个静态变量数组, if(strpos($name,':')) {//检测是否存在':',来判断是否指定基础模型 list($class,$name) = explode(':',$name);//list函数将拆分的字符串分别赋值 }else{ $class = 'Model'; } if (!isset($_model[$name . '_' . $class])) $_model[$name . '_' . $class] = new $class($name,$tablePrefix,$connection);//检测之前是否已经存在这个模型,没有则将新定义的类模型存入静态变量中 return $_model[$name . '_' . $class];//将新定义的模型返回}
我个人感觉这个函数最大的功能就是避免重复实例化模型,如果已经存在的模型,则直接从内存中调取,效率上很给力~~当然我个人没有做实际的试验和数据比测,只是在理论上判断,针对
if(strpos($name,':')) {//检测是否存在':',来判断是否指定基础模型
阅读全文
0 0
- thinkphp源码讲解——Model.class.php
- [李景山php]thinkphp核心源码注释|Model.class.php
- thinkphp核心源码注释|Think.class.php
- thinkphp核心源码注释|Storage.class.php
- thinkphp核心源码注释|Route.class.php
- thinkphp核心源码注释|Log.class.php
- thinkphp核心源码注释|Hook.class.php
- thinkphp核心源码注释|DB.class.php
- thinkphp核心源码注释|Controller.class.php
- thinkphp核心源码注释|Cache.class.php
- thinkphp核心源码注释|Build.class.php
- thinkphp核心源码注释|App.class.php
- thinkphp核心源码注释|Disaptcher.class.php
- thinkphp核心源码注释|Taglib.class.php
- thinkphp核心源码注释|Cx.class.php
- thinkphp核心源码注释|Html.class.php
- thinkphp核心源码注释|File.class.php
- 【thinkphp3.x】ThinkPHP/Lib/Core/Model.class.php文件分析
- numpy 基础学习笔记(2)
- bootstrap下拉列表多选组件
- Kali Linux 安装QT
- 数据库表间的联系
- 做程序员,只盯着自己写了几万行那就跑偏啦!
- thinkphp源码讲解——Model.class.php
- 互联网协议入门(一)
- 5个工具、提示和技巧,优化你的搜索引擎优化输出
- Linux如何理解用数字表示文件的操作权限
- Vue生态——vue-router
- 在网页上实现大华视频监控摄像头在线
- 面试登记表样式
- codeforces 837D Round Subset (dp)
- Common(十六)—— ShowFPS显示帧数