博客列表 >模型数据类型转换

模型数据类型转换

依然很m丶的博客
依然很m丶的博客原创
2018年08月30日 22:31:441372浏览

Index:

<?php
namespace app\index\controller;
use \app\index\model\Shop_name;
class Index
{
    public function index()
    {
        $shop = Shop_name::get(35);
        $shop->name ='java123';
        $shop->price='15';
        $shop->time='2018-2-4';
        $shop->type='java';
        $shop->isUpdate(true)->save();
        $result = Shop_name::get(35);
        dump($result->name);
        dump($result->price);
        dump($result->time);
        dump($result->type);
        echo "原始数据"."<hr>";
        dump($shop->getData());
    }
}

model/Shop_name:

namespace app\index\model;
use think\Model;
class Shop_name extends Model
{
    protected $type= [
        'name'=>'array',
        'price'=>'integer',
        'time'=>'timestamp:Y/m/d' //自定义格式
        ];
}

输出结果:

array(1) {
  [0] => string(7) "java123"
}
int(15)
string(10) "2018/02/04"
string(4) "java"
原始数据array(5) {
  ["id"] => int(35)
  ["name"] => string(11) "["java123"]"
  ["price"] => int(15)
  ["time"] => int(1517673600)
  ["type"] => string(4) "java"
}



声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议