I have a route defined with an annotation, like this:
/**
* @Route("/doSomething/{param}", name="route_name", defaults={"param"=1})
*/
Is it possible to use a class constant instead of this hardcoded '1', like:
/**
* @Route("/doSomething/{param}", name="route_name", defaults={"param"=MyBundle:MyEntity:DEFAULT_TYPE})
*/
(of course the above fails)
Yes you can use constants in annotations, just use the FQN of the class:
/**
* @Route("/doSomething/{param}", name="route_name", defaults={"param"=Namespace\MyBundle\MyEntity::DEFAULT_TYPE})
*/
If you are in the same namespace, or you import the class holding the constant, you can shorten it:
use Namespace\MyBundle\MyEntity;
/**
* @Route("/doSomething/{param}", name="route_name", defaults={"param"=MyEntity::DEFAULT_TYPE})
*/
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