12

When I visit http://localhost/web/app_dev.php I get a very nice web debug toolbar but It doesn't appear in the views rendered by "custom" controllers.

What to do so the debug toolbar to be visible in the views rendered by controllers ?

Here is an example of the controller I use

namespace SD\BlogBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class ContactsController extends Controller
{
    public function indexAction()
    {
        $data = 'Lorem ipsum';

        return $this->render('SDBlogBundle:Default:index.html.twig', array('data' => $data));
    }
}

4 Answers 4

51

The toolbar inserts itself in pages by looking for a terminating </body> tag on your generated page.

If you don't have a </body> tag in your page the toolbar will not appear.

You also need to make sure you're using the dev mode by accessing the page via app_dev.php, e.g.

http://example.com/app_dev.php/hello/world

4

If it doesn't appear in "custom" controllers as you said, but appears in others, you probably have invalid html code.

Symfony2 only shows toolbar if your controller renders HTML. If it's invalid, it can't know it's HTML.

Reason: If your controller returns some other type (such as XML or JSON), Adding toolbar there would not just be useless but also break stuff.

Solution: Check your html code and fix errors in it, toolbar will appear

0

In order to have the Symfony2 debug toolbar shown in your rendered views you must pass thru a front-controller corresponding to an environment that has the toolbar enabled.

If you are using the standard distribution, only the "dev" environment has it enabled by default. Therefore you must use the app_dev.php front-controller.

0

for me the problem was that I had de meta tag pointing to my prod environment.

then in the template ::base.html.twig in dev

<!--<base href="http://www.exemple.com" />-->

in prod:

<base href="http://www.exemple.com" />

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.