I would like routing these kind of URLs:
/hello/{name}
/en/hello/{name}
/es/hello/{name}
I have created this Controller class:
<?php
namespace Fw\Controllers;
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Fw\Application as FwApplication;
class Hello implements ControllerProviderInterface {
const URL_BASE = '/hello';
const URL_BASE_LOCALE = '/{_locale}/hello';
public function connect(Application $app) {
$controllers = $app['controllers_factory'];
$controllers
->get('/{name}/', array($this, 'nameAction'))
->bind('hello_name')
;
return $controllers;
}
public function nameAction(FwApplication\ApplicationBase $app, Request $request, $name) {
return new Response('Hello ' . $name, 200);
}
}
And it has been registered in this way:
$app->mount(FwControllers\Hello::URL_BASE_LOCALE, new FwControllers\Hello());
$app->mount(FwControllers\Hello::URL_BASE, new FwControllers\Hello());
This URL works good: /hello/foo But this one not: /en/hello/foo, this error is shown:
NotFoundHttpException in RouterListener.php line 125: No route found for "GET /en/hello/foo/"
It seems that the second "mount" sentence is overwritten to first one.
Can anybody help me with this problem? How can I set routing with optional {_locale}?
Thanks.