学习内容:
视频教程:
https://www.kancloud.cn/tpshop/thinkphp5/229630
完全开发手册:https://www.kancloud.cn/manual/thinkphp5/138904
教程中的代码:https://github.com/phpervip/tp5a
这一节内容比较简单
controller 中写:
<?php
// application/index/controller/index3.php
namespace app\index\controller;
use app\index\model\Region;
use think\Controller;
use app\index\model\ShippingArea;
use app\index\model\User as mUser;
class index3 extends Controller
{
public function test2(){
$user = mUser::get(1);
// 模型输出
// var_dump($user->toArray());
// echo $user->toJson();
// 隐藏属性
// 隐藏一些属性输出
// echo $user->hidden(['reg_time'])->toJson();
// 指定属性
// 指定一些属性输出
// echo $user->visible(['reg_time'])->toJson();
// 追加属性
// 如果读取器定义了一些非数据库字段的读取,例如:
// var_dump($user->append(['user_status'])->toArray());
/// echo($user->append(['user_status'])->toJson());
// 输出Json
echo $user;
}
}
技术改变命运,学习成就梦想
凡事不难,勿生恐惧,专一,钻研,熟能生巧