Blogger Information
Blog 11
fans 0
comment 0
visits 9289
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
字段映射
The Wolf Of Faith
Original
1621 people have browsed it
<?php
    namespace Home\Model;
    use Think\Model;
    class UserModel extends Model
    {
        protected $_table = array('name'=>'username','pwd'=>'password');
    }

上面代码可以实现在表单提交数据时,可以使用name,pwd名称作为表单数据提交.如果使用create方法创建数据时,会自动转换成定义的实际数据表字段. ps:字段映射还可以支持对主键的映射.

使用字段映射后,默认不会对读取的数据会自动处理
eg:
// 实例化User模型
$User = D('User');
$data = $User->find(3);
dump($data);

输出结果为:
array(size=4) 'id' => int 3 'username'=> string 'apple'(length=5) 'email' => string 'apple@icloud.com' (length=16) 'status' => int 1

这个时候取出的data数据包含的是实际的username和email字段。 

总结:通过find方法读取后的data数据中就包含了name和mail字段数据了,而不再有username和email字段数据了.

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post