symfony-routing

Access global parameters from route condition expressions in Symfony

混江龙づ霸主 提交于 2019-12-04 12:31:25
I'm trying to access app-wide symfony parameters (defined in app/config/parameters.yml) from an expression in a route condition ( documentation ). I tried my luck inserting the parameter within percentage signs and through the function "parameter" (as described for DI here ), both to no avail. Here is the example with the parameter function: example_route: path: /example/{_locale} condition: "request.getLocale() in parameter('locales_array')" defaults: _controller: "AcmeExampleBundle:Example:index" _locale: %locales_default% However I'm getting: SyntaxError - The function "parameter" does not

Symfony2: No route found for “GET /lucky/number”

半世苍凉 提交于 2019-12-03 23:50:53
I start the tutorial (as newbie) and everythings works fine till: http://symfony.com/doc/current/book/page_creation.html#creating-a-page-route-and-controller at step Creating a Page: Route and Controller I have created a file called /var/www/html/[projekt]/src/AppBundle/Controller/LuckyController.php but when I open http://[Server-IP]:8000/app_dev.php/lucky/number is always get a 404: No route found for "GET /lucky/number" 404 Not Found - NotFoundHttpException 1 linked Exception: ResourceNotFoundException » [2/2] NotFoundHttpException: No route found for "GET /lucky/number" + [1/2]

Symfony - generate url with parameter in controller

南楼画角 提交于 2019-12-03 04:42:29
问题 I want to generate a Url directly in my controller. I want to user a url defined in my routing.yml file that needs a parameter. I've found that code in the Cookbook (Routage section) : $params = $router->match('/blog/my-blog-post'); // array('slug' => 'my-blog-post', '_controller' => 'AcmeBlogBundle:Blog:show') $uri = $router->generate('blog_show', array('slug' => 'my-blog-post')); // /blog/my-blog-post But I don't understand to what is refering the $router. Obviously, it doesn't work. Is

Symfony 4 global route prefix

拜拜、爱过 提交于 2019-11-29 12:29:51
I can't find any info about the global route prefix in a Symfony 4 application. The only thing I've found is annotating the controllers with @route . But I don't use annotations and I need all the controllers to have the same prefix. Now I could do that in S3 like this in the app/config/routing.yml file: app: resource: '@AppBundle/Controller/' type: annotation prefix: /foo But S4 is bundleless and I can't do the same - I would have to create a bundle which I don't need. Is it possible to define a global route prefix in Symfony 4 at all or I'm going to end up with prefixing every single root

Symfony 3 Redirect All Routes To Current Locale Version

五迷三道 提交于 2019-11-29 02:35:56
I am working on a symfony application where my goal is no matter what page the user is on it will navigate to the locale version of the page. For example, if the user navigates to "/" the home page, it will redirect to "/en/" If they are on "/admin" page it will redirect to "/en/admin" , in such a way that the _locale property is set from the route. Also it needs to determine the locale if they visit /admin from the users browser since no locale was determined so it knows which page to redirect to. Currently my default controller looks like below since I'm testing. I'm using the dev mode &

Symfony 4 global route prefix

喜夏-厌秋 提交于 2019-11-28 06:50:41
问题 I can't find any info about the global route prefix in a Symfony 4 application. The only thing I've found is annotating the controllers with @route . But I don't use annotations and I need all the controllers to have the same prefix. Now I could do that in S3 like this in the app/config/routing.yml file: app: resource: '@AppBundle/Controller/' type: annotation prefix: /foo But S4 is bundleless and I can't do the same - I would have to create a bundle which I don't need. Is it possible to

Symfony 3 Redirect All Routes To Current Locale Version

微笑、不失礼 提交于 2019-11-27 22:00:44
问题 I am working on a symfony application where my goal is no matter what page the user is on it will navigate to the locale version of the page. For example, if the user navigates to "/" the home page, it will redirect to "/en/" If they are on "/admin" page it will redirect to "/en/admin" , in such a way that the _locale property is set from the route. Also it needs to determine the locale if they visit /admin from the users browser since no locale was determined so it knows which page to

How does the login check_path route work without default controller/action?

元气小坏坏 提交于 2019-11-26 20:24:33
I am working on symfony 2.3 project having the following routing code just2_frontend_logincheck: pattern: /login_check It doesn't have defaults:{ _controller: testBundle:User:login } But it is working. But I don't know how the routing is working. Is it possible? Please advice me about the routing. Nicolai Fröhlich The check_path route/path is used by your firewall to catch login requests. This route's action is never really accessed. It's the route/url your login form posts to and the request should be processed by your firewall's provider service. If the check_path route's action is being

How to get current route in Symfony 2?

南笙酒味 提交于 2019-11-26 17:06:42
How do I get the current route in Symfony 2? For example, routing.yml : somePage: pattern: /page/ defaults: { _controller: "AcmeBundle:Test:index" } How can I get this somePage value? From something that is ContainerAware (like a controller): $request = $this->container->get('request'); $routeName = $request->get('_route'); Matthieu With Twig : {{ app.request.attributes.get('_route') }} I think this is the easiest way to do this: class MyController extends Controller { public function myAction($_route) { var_dump($_route); } ..... Symfony 2.0-2.1 Use this: $router = $this->get("router");

How to get current route in Symfony 2?

人走茶凉 提交于 2019-11-26 05:07:42
问题 How do I get the current route in Symfony 2? For example, routing.yml : somePage: pattern: /page/ defaults: { _controller: \"AcmeBundle:Test:index\" } How can I get this somePage value? 回答1: From something that is ContainerAware (like a controller): $request = $this->container->get('request'); $routeName = $request->get('_route'); 回答2: With Twig : {{ app.request.attributes.get('_route') }} 回答3: I think this is the easiest way to do this: class MyController extends Controller { public function