php – 如何在OctoberCMS插件中注册中间件?
发布时间:2020-12-13 17:00:29 所属栏目:PHP教程 来源:网络整理
导读:Registering middlewares in Laravel很简单: simply list the middleware class in the $middleware property of your app/Http/Kernel.php class 要么 If you would like to assign middleware to specific routes,you should first assign the middleware
Registering middlewares in Laravel很简单:
要么
但是如何在OctoberCMS插件中完成呢? “Routing and initialization”是否意味着用来代替Kernel.php来注册中间件?如果没有,插件可以在哪里注册自己的中间件? 解决方法
如
Documentation中所述,您可以在plugin.php的boot方法中扩展控制器类;
public function boot() { // Extend Controller Class CmsClassesCmsController::extend(function($controller) { $controller->middleware('MiddlewarePath..'); }); // OR Push it directly to the Kernel // prependMiddleware : Add a new middleware to beginning of the stack. $this->app['IlluminateContractsHttpKernel'] ->prependMiddleware('MiddlewarePath..'); // pushMiddleware : Add a new middleware to end of the stack. $this->app['IlluminateContractsHttpKernel'] ->pushMiddleware('MiddlewarePath..'); } 您也可以将它添加到插件的routes.php文件中: Route::group(['prefix' => 'foo'],function () { Route::get('{slug}',function($slug){ .... })->where('slug','(.*)?')->middleware('PathToMiddleware'); }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |