参考的http://www.ruchee.com/notes/fms/laravel_primer.html
直接使用类代替回调函数
routes.php
route::filter(‘myFilter‘,‘MyFilter‘); Route::get(‘/‘, array( ‘before‘ => ‘myFilter:a,b,c‘, function() { return ‘Hello World‘; } ));
app目录下建立filters目录,建立MyFilter.php
<?php class MyFilter { public function filter($route, $request, $first, $second, $third) { return "{$first} - {$second} - {$third}"; } }
打开项目根目录下的 composer.json 文件,在 classmap 配置项中附加一行 "app/filters"
执行一次 composer dump-autoload
注意:最后两行一定要做,不然会报错
测试地址:http://127.0.0.1:8888/testApp/public/
时间: 2024-11-03 03:26:57