Gasim
Gasim

Reputation: 7961

symfony how to "wildcard everything" route

I want to create a route in Symfony in the following ways: /admin/_api/* and /admin/*. So, overall I want to have a configuration like the following:

/admin/_api/users
/admin/_api/posts
/admin/_api/comments
/admin/_api/* -> (AdminBundle:Error:api)
/admin/*  -> (AdminBundle:Error:html)

Based on the given configuraiton, if a user goes to /admin/_api/test, the router will dispatch to ErrorController::apiAction. If a user goes to /admin/users it will dispatch to ErrorController:htmlAction.

Is there a way to achieve this?

Upvotes: 4

Views: 5528

Answers (1)

john Smith
john Smith

Reputation: 17906

You could try it with requirements, in routing.yml:

# All your routes that should match first.
admin_api_wildcard:
  path:  /admin/_api/{wildcard}
  defaults: { _controller: AdminBundle:Error:api }
  requirements:
      wildcard: .*

Prior to (Symfony 3) it´s pattern instead of path :

Upvotes: 7

Related Questions