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))?