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 8326241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:42:05+00:00 2026-06-09T00:42:05+00:00

I have a problem with the routing in Symfony2. Actually I downloaded the latest

  • 0

I have a problem with the routing in Symfony2.

Actually I downloaded the latest release and run it on my server. The demo works fine.

Now I want to do the following:
I want to create a TestController, this controller should have:

  • an index view
  • a view like hello world
  • a view where i can pass 2 parameters

So I started to create a new controller in the src\Acme\DemoBundle\Controller folder called TestController. Here is the code:

<?php

namespace Acme\DemoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Acme\DemoBundle\Form\ContactType;

// these import the "@Route" and "@Template" annotations
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

class TestController extends Controller
{
    public function indexAction()
    {
        return array();
    }

    public function hello2Action($name1, $name2)
    {
        return array();
    }

    public function helloAction()
    {
        return array();
    }
}

Then I created 3 views in a new folder src\Acme\DemoBundle\Resources\views\Test called hello.html.twig, index.html.twig and hello2.html.twig

Both of them have a content like this

{% extends "AcmeDemoBundle::layout.html.twig" %}

{% block title "Symfony - Demos" %}

{% block content_header '' %}

{% block content %}
    foo!!!
{% endblock %}

Finally I edited the routing.dev.yml and added somthing like this:

_name1:
    resource: "@AcmeDemoBundle/Controller/TestController.php"
    type:     annotation
    prefix:   /test

_name2:
    resource: "@AcmeDemoBundle/Controller/TestController.php"
    type:     annotation
    prefix:   /test/hello

_name3:
    resource: "@AcmeDemoBundle/Controller/TestController.php"
    type:     annotation
    prefix:   /test/hello2/{name1}&{name2}

When i want to run the test controller i get:

No route found for “GET /test/”

What is wrong?
Is it possible to have one view for two controller functions? (like hello() and hello($foo))?

  • 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-09T00:42:07+00:00Added an answer on June 9, 2026 at 12:42 am

    You can also do this:

    1. In routing_dev.yml, make sure you have this:

       _main:
           resource: routing.yml
      
    2. In routing.yml, add something like this:

         AcmeDemoBundle:
            resource: "@AcmeDemoBundle/Resources/config/routing.yml"
            prefix:   /test
      

      You can select the prefix you want in accessing that particular bundle.

    3. In Acme/DemoBundle/Resources/config/routing.yml you can now add your route patterns.

        name1:
            pattern: /
            defaults: { _controller: AcmeDemoBundle:Test:index }
      
        name2:
            pattern: /hello
            defaults: { _controller: AcmeDemoBundle:Test:hello }
      
        name3:
            pattern: /hello2/{name1}/{name2}
            defaults: { _controller: AcmeDemoBundle:Test:hello2 }
      

    And you can now access, route /test, /test/hello and /test/hello2/firstname/lastname’. This is just one way of managing routes in symfony 2. This might help: http://symfony.com/doc/current/book/routing.html

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

Sidebar

Related Questions

I have a problem in routing on the server (IIS6). It works OK on
I again have problem with routing :) When I run application if user is
I have problem whit slugify routing parameter. I want to replace all intervals and
I am new to Rails routing and I currently have a problem and hope
I have a problem with the routing while using the Searchable Plugin of Neil
So I have an interesting problem here. I am using URL Routing to mask
Hi everyone I have a problem with MVC3 routing and areas: My route matches
I have a weird problem with routing. I have an existing website that I
I have a problem with transfer of my project to iis server. At the
I have such a problem: I want one method of the class to handle

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.