symfony2 Routing Symfony routes using Routing.yml


Example

    profile_user_profile:
        path:    /profile/{id}
        defaults: { _controller: ProfileBundle:Profile:profile }
        requirements:
            id: \d+
        methods: [get, delete]

If you decide to use Routing.yml instead of Annotations You can get better view of all routes and easier to search and find one.

It is up to you to chose between Routing.yml and Annotations. You can use both for different routes but this is not best solution.

Annotation @Route() equivalent is:

class ProfileController extends Controller
{
    /**
     * @Route("/profile/{id}", name="profile_user_profile", requirements={"id": "\d+"})
     * @Method("GET", "DELETE")
     */
    public function profileAction($id)
    {
        if (!$id) {
            throw $this->createNotFoundException('User not found.');
        }

        return $this->render('::Profile/profile.html.twig', array('id' => $id));
    }
}