Mark Tepper Mark Tepper - 1 month ago 21
CSS Question

Symfony 2 not rendering Welcome Page as expected

after using Zend Framework 2 for a while, I decided to try out Symfony 2 yesterday. Installation on my Debian Jessie test server went smooth and after commenting out the localhost restrictions in config.php (and also app_dev.php of course) I was able to complete the basic configuration steps (even though I had already taken care of it in the according yaml file previously).
After loading the welcome page, I was pretty surprised when I found out that it heavily differed from what the documentation made me expect.

Unfortunately all I'm seeing is the word "Homepage." and the toolbar along the bottom of the window.

I spent a lot of time searching the web and found a hand full of topics that reflected my experience. None of these were answered though. I found a couple of similar issues, but none of the provided solutions worked for me. My Apache Vhost config is absolutely fine (pointing to the web folder for example) and so is my PHP configuration. I have done zero coding in the Symfony project so far, so it can't have been me who caused the issue. ;) Seriously though, I'm really completely clueless as to what might probably be causing the page to render incorrectly. I can see that there's not a single CSS file loaded in the head part of the source code, which leads me to believe that there's no bootstrapping taking place. But since I have not the slightest experience with Symfony 2, this is just me guessing.
Btw, I double checked, the Acme DemoBundkle is installed. Someone somewhere mentioned that the Welcome Page in the documentation was showing exactly that.

If you guys have any idea, please enlighten me, as I would really like to give Symfony 2 a shot.

[Edit]

I've been digging a little deeper into it this morning, and despite the routing being correct and parsed, he app/Resources/views/default is loaded, where it should load src/Acme/DemoBundle/views/Welcome/index.html.twig

I'm getting closer to the solution. I'll update this post as soon as I resolved the issue.

Answer

I'm not entirely sure that this can be considered best practice, but at least I was able to resolve the issue. Symfony was always loading the DefaultController, which indexAction method renders the default/index.html.twig template:

{% extends 'base.html.twig' %}

{% block body %}
    Homepage.
{% endblock %}

Since I wasn't able to find any other way to make the AcmeDemo Welcome page the default page to load, I changed

* @Route("/", name="homepage"

to

* @Route("/default", name="homepage"

in src/AppBundle/Controller/DefaultController.php

I'm almost certain that there has to be a way to configure any other page to be displayed as default without having to change the defaultController, but I have yet to figure out how.

[Edit]

Alright, got it. I reverted the changes I made to the DefaultController and improved the WelcomeController:

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
.
.
.
class WelcomeController extends Controller
{
    /**
     * @Route("/", name="_welcome")
     .
     .
     .
}

and accordingly in src/Acme/DemoBundle/Resources/config/routing.yml:

_welcome:
    resource: "@AcmeDemoBundle/Controller/WelcomeController.php"
    type:     annotation

Now it's working perfectly fine without any changes to the DefaultController, which was - I believe - far from being best practice, as it's likely a core file.

Like I said, I'm completely new to Symfony 2 and it differs a lot from Zend Framework (for good though!), so what may appear as basic knowledge to you, didn't for me. :)