Blogger Information
Blog 14
fans 0
comment 0
visits 16083
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
模型数据类型转换
依然很m丶的博客
Original
1379 people have browsed it

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"
}



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