Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9223661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:07:32+00:00 2026-06-18T04:07:32+00:00

I have just started using Symfony and I am having a routing problem. Here

  • 0

I have just started using Symfony and I am having a routing problem. Here is the routing fromt the controller:

/**
 * @Route("/social/{name}/", name="_speed1")
 * @Route("/social/drivers/")
 * @Route("/social/drivers/{name}/", name="_driver")
 * @Route("/social/", name="_speed")
 * @Template()
 */
public function unlimitedAction()
{

If I go to speed/social/ or speed/social/bob or speed/social/drivers/ or speed/social/drivers/bob all of those pages render with no problem. However I need the name being passed in so I changed

public function unlimitedAction()
{ 

to

public function unlimitedAction($name)
{

If I go to speed/social/drivers/ or speed/social/drivers/bob it returns fine. However, if I go to speed/social/ then I get the following error:

Controller "MyBundle\Controller\DefaultController::unlimitedAction()" 
requires that you provide a value for the "$name" argument (because there is 
no default value or because there is a non optional argument after this one).

I can’t understand why it works for one route but not the other.

So my question is, how can I acheive my routing so that I can go to:

speed/social/
speed/social/drivers/
speed/social/drivers/bob

And be able to pass the variable to the action without error.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:07:33+00:00Added an answer on June 18, 2026 at 4:07 am

    To answer your question: you have to provide a default value for name parameter, for each route without the {name} parameter in the url. I can’t test it right now and I can’t remember the syntax when using annotations, but should be something like this:

    /**
     * @Route("/social/{name}/", name="_speed1", defaults={"name"=null})
     * @Route("/social/drivers/{name}/", name="_driver", defaults={"name"=null})
     * @Template()
     */
    public function unlimitedAction($name)
    {
    }
    

    This way you should be able to call /social/ and /social/foo as well as /social/drivers/ and /social/drivers/foo.

    But, really, this is not the right way to go. Just define more actions, each binded to a single route:

    /**
     * @Route("/social", name="social_index")
     * @Template()
     */
    public function socialIndexAction() { } // /social
    
    /**
     * @Route("/social/{name}", name="social_show")
     * @Template()
     */
    public function socialShowAction($name) { } // /social/foo
    

    As a general rule, each method (each action) should be focused to do just one thing and should be as short as possible. Use services and make your controllers do what they are supposed to do: understand user input, call services and show views.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started using OutputCache on some of my controller actions and I
I have just started using OutputCache on some of my controller actions and I
I have just started using StructureMap, having previously worked with Spring.Net. I love the
I have just started using Tkinter for a programming class and am having a
I have just started using Ember.js framework and I have simple problem. I have
I have just started using MEF and have hit on an early problem. I
I have just started using LINQ to XML , and I am having trouble getting the
I have just started using Eclipse PDT, and I have a similar problem to
I have just started using Rhino mocks and I am having difficulty doing that.
we have just started using a git account of our Django website project so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.