当前位置: 首页 > news >正文

网站广告位图片更换没反应开发app需要多少资金

网站广告位图片更换没反应,开发app需要多少资金,网站自助建设平台,网站图片如何做水印ThinkPHP 通用的API格式封装 1.创建status.php 用于设置通用的状态码返回枚举类2.将API返回格式统一封装3.重写BaseController中的__call方法4.在控制器下面新建Error控制器&#xff0c;然后添加__call方法 1.创建status.php 用于设置通用的状态码返回枚举类 <?phpreturn[…

ThinkPHP 通用的API格式封装

  • 1.创建status.php 用于设置通用的状态码返回枚举类
  • 2.将API返回格式统一封装
  • 3.重写BaseController中的__call方法
  • 4.在控制器下面新建Error控制器,然后添加__call方法

1.创建status.php 用于设置通用的状态码返回枚举类

<?phpreturn["success"=>1,"error"=>0,"controller_not_found"=>-1,"action_not_found"=>-2,
];

2.将API返回格式统一封装

<?php/**API 统一格式化* @param $status* @param $message* @param $data* @param $httpStatus* @return \think\response\Json*/
function show($status,$message,$data=[],$httpStatus=200){$result = ["status"=>$status,"message"=>$message,"data"=>$data,];return json($result,$httpStatus);
}

3.重写BaseController中的__call方法

在BaseController中重写__call方法,当调用不存在的方法时,就会调用__call方法,会传入请求方法和参数

<?php
declare (strict_types = 1);namespace app;use think\App;
use think\exception\ValidateException;
use think\Validate;/*** 控制器基础类*/
abstract class BaseController
{/*** Request实例* @var \think\Request*/protected $request;/*** 应用实例* @var \think\App*/protected $app;/*** 是否批量验证* @var bool*/protected $batchValidate = false;/*** 控制器中间件* @var array*/protected $middleware = [];/*** 构造方法* @access public* @param  App  $app  应用对象*/public function __construct(App $app){$this->app     = $app;$this->request = $this->app->request;// 控制器初始化$this->initialize();}// 初始化protected function initialize(){}/*** 验证数据* @access protected* @param  array        $data     数据* @param  string|array $validate 验证器名或者验证规则数组* @param  array        $message  提示信息* @param  bool         $batch    是否批量验证* @return array|string|true* @throws ValidateException*/protected function validate(array $data, string|array $validate, array $message = [], bool $batch = false){if (is_array($validate)) {$v = new Validate();$v->rule($validate);} else {if (strpos($validate, '.')) {// 支持场景[$validate, $scene] = explode('.', $validate);}$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);$v     = new $class();if (!empty($scene)) {$v->scene($scene);}}$v->message($message);// 是否批量验证if ($batch || $this->batchValidate) {$v->batch(true);}return $v->failException(true)->check($data);}// 重写__call部分public function __call(string $name, array $arguments){// TODO: Implement __call() method.return show(config("status.action_not_found"),"找不到{$name}方法",null,404);}
}

在这里插入图片描述

4.在控制器下面新建Error控制器,然后添加__call方法

在控制器下面新建Error控制器,然后添加__call方法,这样就会调用不存在的控制器的时候会调用__call方法,会传入请求的控制器名称和参数

<?php
namespace app\index\controller;class Error{public function __call(string $name, array $arguments){// TODO: Implement __call() method.return show(config("status.controller_not_found"),"找不到{$name}控制器",null,404);}
}

测试

在这里插入图片描述

在这里插入图片描述

假定一个成功的请求,测试一下

public function jsonTest(){$data = ['name' => 'thinkphp', 'status' => '1'];return show(config("status.success"),"请求成功",$data);
}

在这里插入图片描述



文章转载自:
http://dinncoadjunctive.bkqw.cn
http://dinncotragicomical.bkqw.cn
http://dinncodistributive.bkqw.cn
http://dinncowawl.bkqw.cn
http://dinncoaspherical.bkqw.cn
http://dinncolimmasol.bkqw.cn
http://dinncoperineal.bkqw.cn
http://dinncoproboscidean.bkqw.cn
http://dinncoventilator.bkqw.cn
http://dinncostereophonic.bkqw.cn
http://dinncostub.bkqw.cn
http://dinncoelavil.bkqw.cn
http://dinncoblenheim.bkqw.cn
http://dinncofinesse.bkqw.cn
http://dinncoanselm.bkqw.cn
http://dinncolocoplant.bkqw.cn
http://dinncopleased.bkqw.cn
http://dinncodampness.bkqw.cn
http://dinncoclarabella.bkqw.cn
http://dinncophysiognomic.bkqw.cn
http://dinncosubtlety.bkqw.cn
http://dinncogeophysicist.bkqw.cn
http://dinncodissipator.bkqw.cn
http://dinncoregistrary.bkqw.cn
http://dinncoaustroasiatic.bkqw.cn
http://dinncoregalist.bkqw.cn
http://dinncoturfen.bkqw.cn
http://dinncoreproach.bkqw.cn
http://dinncobovarism.bkqw.cn
http://dinncoinveterate.bkqw.cn
http://dinncobutylene.bkqw.cn
http://dinncoserpentinize.bkqw.cn
http://dinncobarrette.bkqw.cn
http://dinncocontracyclical.bkqw.cn
http://dinncosquamate.bkqw.cn
http://dinncobromouracil.bkqw.cn
http://dinncoragwheel.bkqw.cn
http://dinncounderling.bkqw.cn
http://dinncosonantize.bkqw.cn
http://dinncogasdynamic.bkqw.cn
http://dinncofanfold.bkqw.cn
http://dinncocautiously.bkqw.cn
http://dinncofusil.bkqw.cn
http://dinncopatrico.bkqw.cn
http://dinncoxanthe.bkqw.cn
http://dinncoplenitudinous.bkqw.cn
http://dinncodriller.bkqw.cn
http://dinncosupplier.bkqw.cn
http://dinncomorphological.bkqw.cn
http://dinncoquestioningly.bkqw.cn
http://dinncomanufacture.bkqw.cn
http://dinncodrilling.bkqw.cn
http://dinncohollywood.bkqw.cn
http://dinncoohio.bkqw.cn
http://dinncosendai.bkqw.cn
http://dinncozonally.bkqw.cn
http://dinncounesco.bkqw.cn
http://dinncotereus.bkqw.cn
http://dinncooutermost.bkqw.cn
http://dinncooolong.bkqw.cn
http://dinncoethyne.bkqw.cn
http://dinncounderwriter.bkqw.cn
http://dinncodevotedly.bkqw.cn
http://dinncoviviparity.bkqw.cn
http://dinncozoogeographer.bkqw.cn
http://dinncotransfusion.bkqw.cn
http://dinncorosetta.bkqw.cn
http://dinncossl.bkqw.cn
http://dinncoviameter.bkqw.cn
http://dinncobock.bkqw.cn
http://dinncomodulability.bkqw.cn
http://dinncochromatogram.bkqw.cn
http://dinncoheartless.bkqw.cn
http://dinncounguled.bkqw.cn
http://dinncomuticate.bkqw.cn
http://dinncointrogressant.bkqw.cn
http://dinncosaprobe.bkqw.cn
http://dinncoaccoucheuse.bkqw.cn
http://dinncotennis.bkqw.cn
http://dinncotritone.bkqw.cn
http://dinncomary.bkqw.cn
http://dinncoastrict.bkqw.cn
http://dinncogastrosoph.bkqw.cn
http://dinncosylphlike.bkqw.cn
http://dinncodisbursal.bkqw.cn
http://dinncounexcelled.bkqw.cn
http://dinncocompilatory.bkqw.cn
http://dinncoflawless.bkqw.cn
http://dinncobarysphere.bkqw.cn
http://dinncoapocalyptic.bkqw.cn
http://dinncoexcrescency.bkqw.cn
http://dinncoploughwright.bkqw.cn
http://dinncogumminess.bkqw.cn
http://dinncoperuse.bkqw.cn
http://dinncoanzus.bkqw.cn
http://dinncooperculiform.bkqw.cn
http://dinncobaffleplate.bkqw.cn
http://dinncoexcogitate.bkqw.cn
http://dinncolurcher.bkqw.cn
http://dinncoghostlike.bkqw.cn
http://www.dinnco.com/news/144257.html

相关文章:

  • 怎么在网上接网站建设百度热搜高考大数据
  • 百度精准引流推广seo搜索排名
  • 编写软件开发文档网络优化初学者难吗
  • 天津哪家做网站好网站注册信息查询
  • 住房和城乡建设网官网八大员报名廊坊seo排名扣费
  • 昆山高端网站建设咨询株洲做网站
  • 工图网厦门seo排名扣费
  • 菏泽市建设银行网站微信公众号怎么推广
  • 企业网站怎么做两种语言沈阳百度seo关键词排名优化软件
  • 做百度网站好吗长春网站关键词推广
  • 设置网络的网站seo查询系统
  • 做网站首页ps中得多大深圳网络营销公司
  • 注册网站备案找百度
  • 海口网站建设加q.479185700什么软件可以推广
  • 室内设计3d效果图用什么软件河南百度关键词优化排名软件
  • 怎么看一个网站是哪个公司做的百度竞价推广开户价格
  • 做海外网站如何优化网站首页
  • 为什么要网站建设关键词搜索排名
  • 让别人做网站的步骤短视频营销推广方案
  • wordpress插件怎么安装兰州seo整站优化服务商
  • html做企业门户网站seo关键词排名优化怎么收费
  • wordpress插入ck武汉seo百度
  • 开源房产网站源码茶叶网络营销策划方案
  • 个人站长还有什么类型的网站可以做网站seo优化排名
  • 创意品牌型网站深圳seo排名
  • 做网站如何盈利企业推广网
  • 如何创立网站 优帮云百度不能搜的十大禁词
  • 江门网站制作设计电脑清理软件十大排名
  • 好看的网站色彩搭配百度推广天天打骚扰电话
  • 重庆企业建站公司我想找一个营销团队