I am using annotations to define routes in controllers and I have 15 controllers. All are executed by /path1
, /path2
.
Is there any way that in all those controller , I can access them via /admin/path1
and /admin/path2
?
I don't want to enter that by changing each file.
Can I do that from a single location? I mean the whole bundle should open via /admin
and then their respective paths.
try this
# app/config/routing.yml
acme_hello:
resource: "@AcmeHelloBundle/Resources/config/routing.yml"
prefix: /admin
or if using annotations
resource: "@AcmeHelloBundle/Controller"
type: annotation
prefix: /admin
Use this in routing.yml
:
Admin:
resource: "@AdminBundle/Controller"
type: annotation
prefix: /admin
Just define the annotation for your Class (not for method)
/**
* @Route("/blog")
*/
http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/routing.html#route-prefix
If you want to prefix specific controller DevController for example and have something like:
myproject.com/dev/test
in your Controller add the following Route annotation as in example:
/**
* @Route("/dev")
*/
class DevController extends Controller{
/**
* @Route("/test")
*/
public function testSavingAction(){
return new Response();
}
....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With