Questions tagged [symfony-routing]

Routing in Symfony Framework's MVC implementation. Symfony is a free, open source PHP web application framework, and it is released under the MIT license.

symfony-routing is a tag suitable for any questions regarding routing in Symfony's MVC implementation, url handling, or any other matter affecting or affected by routing in Symfony.

196 questions
248
votes
13 answers

How to get current route in Symfony 2?

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?
IlyaDoroshin
  • 4,659
  • 4
  • 22
  • 26
61
votes
4 answers

Symfony - generate url with parameter in controller

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'…
user2094540
30
votes
1 answer

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

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…
saravanan
  • 401
  • 1
  • 4
  • 11
22
votes
11 answers

Symfony2: No route found for "GET /lucky/number"

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…
Atreides78
  • 577
  • 1
  • 7
  • 22
14
votes
3 answers

Route is in debug list but returns 404 in Symfony 4

Ok, so I just installed latest version Symfony 4. Run the browser after installation and a nice welcome greeting shows. All good! Then I created a new controller using make:controller. I named this controller Client and is using Annotations, same…
Riza
  • 697
  • 2
  • 10
  • 17
8
votes
4 answers

Symfony2 Routing: Method Not Allowed (Allow: {Method})

so in routing.yml I have the following routes defined in order to edit and delete specific settings: routing.yml: settings.editDefaults: path: settings/{id}/defaults/edit/{widgetType} defaults: { _controller:…
Anth Bieb
  • 395
  • 1
  • 4
  • 11
7
votes
1 answer

PageController can't be requested via XmlHttpRequest in Shopware 6

I am trying to send a request to my custom StorefrontController on the latest Shopware 6.2.2 but I am getting the following error: PageController can't be requested via XmlHttpRequest. I am doing a regular httpClient request as such from a custom…
Huzaifa Mustafa
  • 262
  • 5
  • 18
7
votes
6 answers

Symfony4: No route found for "GET /lucky/number"

I am starting to play with symfony4. I've just created new application and create new LuckyController. It works with routes.yaml configured in this manner: lucky: path: /lucky/number controller: App\Controller\LuckyController::number With…
sensorario
  • 20,262
  • 30
  • 97
  • 159
6
votes
2 answers

Symfony2 Route get parameter only if integer

I got defined routes in routing.yml file one route is: Profile_user_profile: path: /profile/{id} defaults: { _controller: ProfileBundle:Users:profile } methods: [get] and second is: Profile_accept_connection_proposal: path: …
Stevan Tosic
  • 6,561
  • 10
  • 55
  • 110
6
votes
3 answers

How to use anchors in Symfony routing?

I have defined a route as followed in my routing.yml file : route_name: path: "/dashboard#messages/{id}" However when I ask Symfony to generate that route, I get : /dashboard%23messages/12345 How can I skip the encoding part of the route…
i.am.michiel
  • 10,281
  • 7
  • 50
  • 86
6
votes
3 answers

How to automate function name in symfony routing?

Here is the simple route defined in the custom bundle my_admin_route: pattern: /admin/{name} defaults: { _controller: NamespaceCustomBundle:CustomControl:login } Above routing code will call the CustomControlController's method…
M Khalid Junaid
  • 63,861
  • 10
  • 90
  • 118
5
votes
1 answer

Named Routes in Symfony 6 with controllers in inner directory

I moved all my controllers to /src/Web/Controller in my Symfony 6 project like follows ├── src │ ├── ... │ └── Web │ | ├── Controller │ | ├── .... | |── Kernel.php my routes.yaml is modified accordingly #routes.yaml controllers: …
Shobi
  • 10,374
  • 6
  • 46
  • 82
5
votes
1 answer

Why doesn't Symfony 5.1 recognize routes configured on a "routes.php" file?

I'm having a hard time trying to configure my routes using a config/routes.php file in Symfony 5.1. As per the Symfony routing documentation, I should be able to configure my routes in a PHP file: Instead of defining routes in the controller…
Caconde
  • 4,177
  • 7
  • 35
  • 32
5
votes
2 answers

Symfony 4 print all routes

I'm trying to set up an index page which would print out all the endpoints in the API (using Symfony 4). In Symfony 2 you could get a router and via the container and then the collection of the routes. But it seems that you don't have access to the…
RokDev
  • 161
  • 1
  • 10
5
votes
1 answer

Reusing Symfony routes with complicated/many params

I often find myself with routes that require 2+ (sometimes 4+) parameters to generate a route. This is fine as long as I only need to generate the route in a couple spots. But I often find myself reproducing the list of parameters in many locations,…
Darryl Hein
  • 142,451
  • 95
  • 218
  • 261
1
2 3
13 14