Skip to content

Routes of the form /hello/{name} with an optional parameter at the end don't match as expected #5869

Closed
@chrismcmacken

Description

@chrismcmacken

This issue can be reproduced with any brand new install of Symfony 2.1.2, just generate a default bundle and add the below route.

routing.yml file

my_test_homepage:
    pattern:  /hello/{name}
    defaults: { _controller: MyTestBundle:Default:index, name: DefaultName }
DefaultController.php

<?php

namespace My\TestBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{
    public function indexAction($name)
    {
        return $this->render('MyTestBundle:Default:index.html.twig', array('name' => $name));
    }
}

The route will be matched on any urls of the form http://localhost/hello/test (or other strings after hello) but the route will not be matched on urls of the form http://localhost/hello/ even though the parameter should be optional, this example is practically straight out of the Symfony2 documentation so as far as I can tell that's how it should behave.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions