Perhaps its easier to define the Controller over an annotation.
in route.yml:
MineTestBundle:
resource: "@MineTestBundle/Controller/"
type: annotation
Then you can define the route direct in your controller.
/**
* @Route("/foo")
*/
class FooController extends Controller {
/**
* @Route("/", name="_foo_index")
* @Template()
*/
public function indexAction() {
return array();
}
/**
* @Route("/{page}/", name="_foo_page")
* @Template()
*/
public function pageAction($page) {
return array('page' => $page);
}
}
Now when you try to access /foo you come to the indexAction and when you access /foo/1/ you come to the pageAction.
Edit:
Sorry for the misunderstanding. I've tried to reproduce your problem. The easiest way is to define 2 Routes in your config like this:
foo_route:
pattern: /foo/{page}/
defaults: { _controller: AcmeDemoBundle:Foo:list }
requirements:
name: ".+"
foo_route_foo:
pattern: /foo
defaults: { _controller: AcmeDemoBundle:Foo:list, page: 1 }
requirements:
name: ".+"
In the Route without the parameter {page} You can set the page default to 1.
But here in the Cookbook is a chapter How to allow a "/" character in a route parameter so its possible to allow a / in the route so all that comes after /foo/123/234/ is in the variable $page and you can split them for yourself in your function.