How can I go around having a single route that would internally be forwarded to a controller depending on some internal logic. I've looked into dynamic routes but it doesn't help since the route is shared, not dynamically created (ie "my/page")

In symfony I could do this $this->forward('AppBundle:Something:fancy',$params) but I've been unable to do this in Drupal 8.

I also looked into middleware since it looked promising but I couldn't figure out a way of doing it either.

  • If you return a RedirectResponse in your controller you can redirect to another controller depending on your internal logic... – Robin Apr 18 '17 at 18:20
  • You can do a sub-request, but they're not trivial and also not really what you want. Does it really need to be an actual controller? I'd just call out separate methods in your own controller or instantiate another controller/service. – Berdir Apr 18 '17 at 18:53
  • What is the internal logic that you need to change the route based on? – Jaypan Apr 18 '17 at 23:15
  • It's a group of callback routes that the user will be lead to after some off-site operations. The way I have it working is handling from a main controller that diverts to another controller by returning the response, creating an instance of that controller, returning that response. I would think that this could be done with a middleware too, handling only certain routes, and doing the same I'm doing in that controller right now. – Juan Apr 19 '17 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.