On this page
广告列表api
创建相关文件
php
// 创建广告控制器
php think make:controller api/v1/Adsense
// 创建广告模型
php think make:model Adsense
// 创建广告验证器
php think make:validate AdsenseValidate
controller层:application\api\controller\v1\Adsense.php
php
<?php
namespace app\api\controller\v1;
use think\Controller;
use think\Request;
use app\common\validate\AdsenseValidate;
use app\common\model\Adsense as AdsenseModel;
use app\common\controller\BaseController;
class Adsense extends BaseController
{
// 获取广告列表
public function index(){
(new AdsenseValidate())->goCheck();
$list = (new AdsenseModel)->getList();
return self::showResCode('获取成功',['list'=>$list]);
}
}
route层:route\route.php
php
Route::group('api/:v1/',function(){
// 广告列表
Route::get('adsense/:type', 'api/v1.Adsense/index');
});
validate层:application\common\validate\AdsenseValidate.php
php
protected $rule = [
'type'=>'require|integer|in:0,1',
];
model层:application\common\model\Adsense.php
php
// 获取广告列表
public function getList(){
$param = request()->param();
return $this->where('type',$param['type'])->select();
}