I'm using SF2 and I created some routes helping the debugging of the project:
widget_debug_page:
path: /debug/widget/{widgetName}
defaults: { _controller: WidgetBundle:Debug:default }
The problem is that this route MUST never be reachable when going in production.
I could not find a parameter to specify the environment.
Symfony provides a Routing component which allows us, for a HTTP request/URL, to execute a specific function (also known as "Controller"). Note: Controllers must be a callable, for example: an anonymous function: $controller = function (Request $request) { return new Response() }; .
By default, the routing configuration file in a Symfony2 application is located at app/config/routing. yml. Like all configuration in Symfony2, you can also choose to use XML or PHP out of the box to configure routes.
Instead of defining env vars in your shell or your web server, Symfony provides a convenient way to define them inside a . env (with a leading dot) file located at the root of your project. The . env file is read and parsed on every request and its env vars are added to the $_ENV & $_SERVER PHP variables.
As you might know, Symfony2 uses annotations for Doctrine mapping information and validation configuration. Of course, it is entirely optional, and the same can be done with XML, YAML, or even PHP. But using annotations is convenient and allows you to define everything in the same file.
Just for people who want use with annotation
system:
/**
* @Route("/my-route", condition="'dev' === '%kernel.environment%'")
*/
public function index() {}
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