Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony - Defining a route only in dev. environment

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.

like image 887
user2998227 Avatar asked Jan 31 '15 15:01

user2998227


People also ask

How does Symfony routing work?

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() }; .

What is the default routing configuration file in Symfony application?

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.

Where is .ENV file Symfony?

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.

What is Symfony annotation?

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.


1 Answers

Just for people who want use with annotation system:

/**
 * @Route("/my-route", condition="'dev' === '%kernel.environment%'")
 */
public function index() {}
like image 82
Breith Avatar answered Sep 18 '22 23:09

Breith