0

Have looked through SO at various Symfony routing issues but no-one seems to have the same issue as this.

Yesterday, routing worked without issue.

Today I am getting errors regarding values being required for arguments with defaults set

This is an example route that is causing me a problem

@Route("/summary/{staffId}", name="task_instance_summary", requirements={"staffId":"\d+"},defaults={"staffId":"0"})

The method definition:

public function summaryAction(Request $request, $staffId)

and of course the error:

"Controller "PlanXL\TaskBundle\Controller\InstanceController::summaryAction()" requires that you provide a value for the "$staffId" argument (because there is no default value or because there is a non optional argument after this one).")

Debug output:

[router] Route "task_instance_summary"

Name task_instance_summary

Path /task/instance/summary/{staffId}

Path Regex #^/task/instance/summary(?:/(?P\d+))?$#s

Host ANY

Host Regex

Scheme ANY

Method ANY

Class Symfony\Component\Routing\Route

Defaults _controller: PlanXLTaskBundle:Instance:summary

staffId: 0

Requirements staffId: \d+

Options compiler_class: Symfony\Component\Routing\RouteCompiler

I have already cleared the cache (even though I am working on dev) but I can't see why I am getting an error. The router can obviously see the default value when I run the debug so why not when called through my application?

1 Answer 1

3

Try it;

public function summaryAction(Request $request, $staffId = 0)

2
  • I know this will get rid of the error above but I really don't feel like going through my whole application and updating all my routes and method definitions to set default values when previously the annotations were working.
    – Jameel
    Oct 30, 2017 at 14:27
  • Ok, after messing about with converting my routing to yml instead of annotations, and getting the same errors, I gave up and have gone thjrough my application adding default values to my method declarations whenever a route throws the error. Bizarre that only some routes are affected.
    – Jameel
    Oct 31, 2017 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.