Home  >  Article  >  php教程  >  让D函数和M函数更好的支持mongodb

让D函数和M函数更好的支持mongodb

WBOY
WBOYOriginal
2016-06-07 11:43:451326browse

在使用mongodb的时候,如果用默认的ThinkPHP,D函数需要增加MongoModel,M函数需要M('MongoModel:User'),按以下稍作修改可以使代码更少。
通过修改Common/common.php的D函数,如下:function D($name='') {<br>     if (C('DB_TYPE') == 'mongo') return new MongoModel($name);<br>         ...修改Common/common.php的M函数,如下:$class   = C('DB_TYPE') == 'mongo' ? 'MongoModel' : 'Model';可以不用创建对应的MongoModel,直接用D('User')或者M('User')。
使用mongodb可以免去建表和修改schema,在项目中实施很方便。

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn