tp5 field的几个特殊用法
原创 php thinkphp thinkphp5 field 2021-07-26 12:07:28
0 收藏 0 浏览1393 评论0
琴朗
已发33篇
有侵犯版权请及时联系我们,我们将在24小时内删除文章。
投诉举报


很多时候会对查询的字段进行特殊处理,比如在字段前增加链接、将int时间戳转化为日期等等。下面介绍几个常用的用法


1.字段连接

例如,在图片字段前面增加域名

$web = "https://www.yusan.cn";
$Model->field("CONCAT('$web',picture) AS `picture_url`")->find();


2.将时间戳转为日期

//已知添加日期字段(create_time)是时间戳,转化后就是年-月-日 时:分:秒
$Model->field(["from_unixtime(create_time,'%Y-%m-%d %H:%i:%s') as `create_time`"])->find();


评论(0) 我要评论