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"
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号