0

Here's a problem I've got to face a lot and I think that many people are having the same problem:

I try to call an action in controller and then to redirect to the URL I came from. Let me show you the code:

I've got a basic form whose parameters are like that:

<form id="messageCreationForm" action="{{ path('createMessage') }}" method="POST">

Submitting call the following method:

    /**
     * @Route("/createMessage", name="createMessage")
     * Request $request
     */
    final public function createMessageAction(Request $request)
    {
    //Some logic...
        return $this->generateUrl(
            '/agent/campagne',
            [
                'agent' => $agent,
                'entretiens' => $talentMatchJobs
            ]
        );
    }

Then, i got this error:

Unable to generate a URL for the named route "/agent/campagne" as such route does not exist.

However, the route exists:

enter image description here (I'm not allowed to submit image here so, click on the link to see it..)

I've also tried routes :

/campagne, campagneIndex, campagne...

The corresponding method that defines the route is this one (this route give me the url /agent/campagne:

/**
 * @Route("/campagne", name="campagneIndex")
 * @return Response
 */
final public function campagneIndexAction()
{
//Some logic...
}

I would really appreciate some help.. Thank you Regards,

Maxime

O'Neil
  • 3,790
  • 4
  • 16
  • 30
MaximeADT
  • 1
  • 1

1 Answers1

1

the generateUrl method take a route name as first parameter. here you need to use "campaignIndex" to be able to generate the "/agent/campagne" url.

if this doesn't work you can try to clear your cache or launch the debug:router command to see if the route is correct

Benoît
  • 594
  • 4
  • 11