0
votes

Simple case. In my all app I'm using Route annotation driver, defined in routing.yml as follows:

MyBundle:
    resource: "@MyBundle/Controller/"
    type:     annotation
    prefix:   /someprefix

Some action in MyBundle's Ctrl controller looks like:

@Route("/{page}/{status}", name="default_action", defaults={"page" = 1, "status" = "ok"}, requirements={"page" = "\d+"})
public function defaultAction($page, $status) {...}

Now I want to make this action - default action when visiting my web page. I cannot use just @Route("/") because I'm prefixed. So I'm adding to routing.yml:

_welcome:
    pattern:  /
    defaults: { _controller: MyBundle:Ctrl:default }

And there is where problem starts - Symfony2 is calling default controllers action not from annotation but just from action and I get error:

Controller "...:defaultAction()" requires that you provide a value for the "$page" argument (because there is no default value or because there is a non optional argument after this one).

So simply Symfony2 is not obtaining default values from @Route annotation.

Question is: how to call route for _welcome that is aware of @Route?

1

1 Answers

0
votes

You've missed defaults in yml settings, should look like this:

_welcome:
    pattern:  /
    defaults: { _controller: MyBundle:Ctrl:default, page: 1, status: ok }