中间件的使用
系统级中间件可以在Config夹下新建
\Config\Middleware.php
return [// \SilangPHP\Middleware\SystemtestMiddleware::class];
<?phpnamespace App\Controller;use App\Middleware\HelloMiddleware;use App\Middleware\TestMiddleware;class IndexController extends \SilangPHP\Controller{// 要运行的中间件public $middlewares = [HelloMiddleware::class,TestMiddleware::class];// 只能运行的Actionpublic $onlyAction = [];// 不能运行的Actionpublic $exceptAction = [];// onlyAction和exceptAction不同即所有Action都使用中间件public function index(\SilangPHP\Request $request){echo 'action内容:index'.lr;}public function index2(){echo 'index3';}}
输出
中间件test start
中间件hello start
action内容:index
中间件hello end
中间件test end
