Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy this Symfony2 routing is not working?
    text
    copied!<p>I have a problem with the routing in Symfony2.</p> <p>Actually I downloaded the latest release and run it on my server. The demo works fine.</p> <p>Now I want to do the following: I want to create a TestController, this controller should have:</p> <ul> <li>an index view</li> <li>a view like hello world</li> <li>a view where i can pass 2 parameters</li> </ul> <p>So I started to create a new controller in the <code>src\Acme\DemoBundle\Controller</code> folder called <code>TestController</code>. Here is the code:</p> <pre><code>&lt;?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(); } } </code></pre> <p>Then I created 3 views in a new folder <code>src\Acme\DemoBundle\Resources\views\Test</code> called <code>hello.html.twig</code>, <code>index.html.twig</code> and <code>hello2.html.twig</code></p> <p>Both of them have a content like this</p> <pre><code>{% extends "AcmeDemoBundle::layout.html.twig" %} {% block title "Symfony - Demos" %} {% block content_header '' %} {% block content %} foo!!! {% endblock %} </code></pre> <p>Finally I edited the <code>routing.dev.yml</code> and added somthing like this:</p> <pre><code>_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}&amp;{name2} </code></pre> <p>When i want to run the test controller i get:</p> <blockquote> <p>No route found for "GET /test/"</p> </blockquote> <p>What is wrong? Is it possible to have one view for two controller functions? (like hello() and hello($foo))?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload