垃圾 / yaml-route-service-provider
Silex 服务提供者,用于使用 YAML 路由文件
0.2.2
2020-06-18 18:25 UTC
Requires
- silex/silex: ^2.0
- symfony/config: ~3.0|~4.0
- symfony/yaml: ~3.0|~4.0
Requires (Dev)
- symfony/browser-kit: ~3.0|~4.0
README
Silex 服务提供者,用于使用 YAML 路由文件
要求
silex 2.x
安装
安装 YamlRouteServiceProvider 的最佳方式是使用 Composer
php composer.phar require junker/yaml-route-service-provider
示例
use Junker\Silex\Provider\YamlRouteServiceProvider; $app->register(new YamlRouteServiceProvider('routes.yml')); # or $app->register(new YamlRouteServiceProvider('routes.yml', ['cache_dir' => '/tmp/routes_cache']));
路由配置示例
# routes.yml home: path: / defaults: { _controller: 'Acme\Controller\AppController::indexAction' } articles.list: path: /articles defaults: { _controller: 'Acme\Controller\ArticlesController::indexAction' } articles.view: path: /articles/{slug} defaults: { _controller: 'Acme\Controller\ArticlesController::viewAction' }
控制器示例
# Acme\Controller\ArticlesController.php use Silex\Application; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; namespace Acme\Controller; class ArticlesController { public function indexAction(Request $request, Application $app) { ... return new Response($articles); } public function viewAction(Request $request, Application $app, $slug) { ... return new Response($article); } }