Ikzer
Ikzer

Reputation: 539

Symfony2 existing route error

I'm having problems to figure out where exactly I have the error when getting this message:

An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "core" as such route does not exist.") in app/Resources/views/globalheader.html.twig at line 3.

The globalheader.html.twig is:

{# app/Resources/views/globalheader.html.twig #}
<div id="globalheader">
    <h1><a href="{{ path('core') }}">MyListProject</a></h1>
    <div class="usermenu">
    {% block globalheader_usermenu %}{% endblock %}
    </div>
</div>

The routing.yml:

user:
    resource: "@UserBundle/Resources/config/routing.yml"
    prefix:   /user

rpg_db:
    resource: "@RPGBundle/Resources/config/routing.yml"
    prefix:   /rpg

core:
    resource: "@CoreBundle/Controller/"
    type:     annotation
    prefix:   /

And the CoreBundle DefaultController:

namespace MyProject\System\CoreBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

class DefaultController extends Controller
{
    /**
     * @Route("/")
     * @Template()
     */
    public function indexAction($name = null)
    {
        return array();
    }
}

What am I doing wrong? Or where else could be my problem?

Upvotes: 0

Views: 72

Answers (1)

ReynierPM
ReynierPM

Reputation: 18660

Add the name to your Route definition:

class DefaultController extends Controller
{
    /**
     * @Route("/", name="core")
     * @Template()
     */
    public function indexAction($name = null)
    {
        return array();
    }
}

Upvotes: 1

Related Questions