Silex Service provider for using YAML routing files
silex 1.x
The best way to install YamlRouteServiceProvider is to use a 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 config example:
# 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' }
Controller example:
# Acme\Controller\ArticlesController.php
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);
}
}