美文网首页
[PHP高可用后端]③0--API接口版本控制

[PHP高可用后端]③0--API接口版本控制

作者: 子木同 | 来源:发表于2017-11-22 14:24 被阅读324次
微信截图_20171122142221.png

route.php

<?php

use think\Route;

Route::get('test', 'api/test/index');
Route::put('test/:id', 'api/test/update');

Route::resource('test', 'api/test');

Route::get('api/:ver/cat',  'api/:ver.cat/read');

Cat.php

<?php
/**
 * Created by PhpStorm.
 * User: tong
 * Date: 2017/11/22
 * Time: 11:09
 */

namespace app\api\controller\v1;

use app\api\controller\Common;

class Cat extends Common
{

    public function read()
    {
        $cats = config('cat.list');
        /**
         * array (size=4)
         * 1 => string '综艺' (length=6)
         * 2 => string '明星' (length=6)
         * 3 => string '韩娱' (length=6)
         * 4 => string '看点' (length=6)
         */
        //halt($cats);

        $result []= [
            'catid'=>0,
            'catname'=>'首页',
        ];

        foreach ($cats as $catid => $catname) {
            $result[] = [
                'catid' => $catid,
                'catname' => $catname,
            ];
        }
        return show(config('code.success'), 'OK', $result, 200);


    }

}
namespace app\api\controller\v1;

use app\api\controller\Common;
image.png

相关文章

网友评论

      本文标题:[PHP高可用后端]③0--API接口版本控制

      本文链接:https://www.haomeiwen.com/subject/abwnvxtx.html