开新项目:
1.先安装好各种应用,composer,php命令行,等等,配置好国内源
2.下载好cmf,通过命令行进入项目目录,修改composer.json,然后执行composer update
例如安装jwt:
"require": {
"thans/tp-jwt-auth": "^1.1"
},
3.如何使用中间件:
1.在模块下创建middleware.php文件里面写,指明过滤器https://www.kancloud.cn/manual/thinkphp5_1/564279
<?php
return [
app\test\auth\Middleware::class,
];
2.根据app\模块名\过滤器文件夹\过滤器文件名,创建过滤器.php,内容如下
<?php
//namespace app\模块名\过滤器文件夹名;
namespace app\demo\middleware;
use app\common\facade\Response;
use thans\jwt\facade\JWTAuth;
use Throwable;
//class 过滤器名
class Auth
{
public function handle($request, \Closure $next)
{
try {
JWTAuth::auth();
} catch (Throwable $e) {
// dump($e);
$message = $e->getMessage();
return json(['code'=>9999,'data'=>$message]);
}
return $next($request);
}
}