多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
1.更改配置项 ~~~ // 默认输出类型 // 'default_return_type' => 'html', 'default_return_type' => 'json', ~~~ 2.让模型中的Banner.php继承think\Model ~~~ <?php namespace app\api\model; use think\Db; use think\Model; class Banner extends Model { public static function getBannerById($id) { //$result=Db::query('select * from banner_item where banner_id=?',[$id]); $result=Db::table('banner_item') ->where( function ($query) use ($id){ $query->where('banner_id','=',$id); } )->select(); return $result; } } ~~~ 3.Banner.php文件 ~~~ <?php namespace app\api\controller\v1; use app\api\validate\IDMustBePostiveInt; use app\api\model\Banner as BannerModel; use app\lib\exception\BannerMissException; class Banner{ //获取指定id的banner信息 public function getBanner($id) { (new IDMustBePostiveInt())->goCheck(); $banner=BannerModel::get($id); if(!$banner){ throw new BannerMissException(); } return $banner; } } ~~~ 结果 ![](https://box.kancloud.cn/713e08096853a38a8c32a4093066659e_550x654.png)