Home> php教程> php手册> body text

解析thinkphp中的M()与D()方法的区别

WBOY
Release: 2016-06-13 11:46:25
Original
1122 people have browsed it

D()和M()方法的区别:
D和M的区别主要在于
M方法不需要创建模型类文件,M方法不会读取模型类,所以默认情况下自动验证是无效的,但是可以通过动态赋值的方式实现
而D方法必须有创建模型类。
我们可以用下面两种方法去创建一个数据表的映射对象
第一种:$Test = D('Test')
第二种:$Test = new Model('Test')
虽然这两种都可以对数据进行select,insert,delete,udpate操作,在
数据验证上有很大的不同,
用第一种方式实例一个模型就会有数据检查功能,如果 title 没有填写的话就会提示 “请输入标题” (这个是tp提供的一个自动验证功能,当然也需要在相应的model中定义好验证条件);
如果用第二种就没有了·····
还有1个区别就是当用了$trueTableName后,必须用$test=d('test'),表示查询的是test表,
如果用的是$test=m('test'),那么都表示查询的数据边是think_test。
thinkphp2.0版本测试有如此上面的问题

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!