限时免费试用:欢迎注册 api.bigmodel.org ,快速体验大模型 API 接入服务。

小程序

tp5+小程序开发笔记(六)

在application/extra下的配置文件都会被tp5自动加载 新建setting.php return[ 'img_prefix'=>'http://wmc.com/images' ] 使用模型的获取器拼接图片路径 tp5中只有public是公开的 public/images/1,jpg config('配置文件.配置名称'); $a = confi

作者
王明昌
发布时间
在application/extra下的配置文件都会被tp5自动加载 新建setting.php
return[
 'img_prefix'=>'http://wmc.com/images'
]

使用模型的获取器拼接图片路径

tp5中只有public是公开的 public/images/1,jpg
config('配置文件.配置名称');
$a = config('setting.img_prefix);
数据库中的图片地址   /1.jpg

model
获取器,当时用时自动调用
函数名:  get字段名Attr
public function getUrlAttr($value,$data){
 if($data['type'] == 1){
//本地的图片
    $a = $value;// /1.jpg 
    return config('setting.img_prefix').$value;
 }else{
//网络完整的地址
    return $value;
 }  
}

api版本

开闭原则 对扩展开放,对修改封闭(版本的替换)
if($version == 1){

}
if($version == 2){

}
路由
v1:
Route::get('api/v1/banner/:id','api/v1.banner/getBanner');
升级版:
Route::get('api/:version/banner/:id','api/:version.banner/getBanner');

完整匹配路由

config.php
'route_complete_match'=>true,

数据集对象

通过数据集临时隐藏字段 1.自己设置数据集
$products =  ProductModel::aaa($a);
$collection = collection($products);
$products = $collection->hidden(['summary']);//临时隐藏summary
2.自动设置数据集 database.php
'resultset_type'=>'collection'   //原生是array

$products = ProductModel::aaa($a); 
$products = $products->hidden(['summary']);//临时隐藏summary

如果查不到不报错返回空数组,使用如下
if($result->isEmpty()){
........
}

接口粒度与接口分层

0/500
友善分享您的看法。
反馈邮箱