1
votes

I am new to Stack Overflow and programming and I have a bad english, so sorry in advance if I don't ask things correctly.

I am learning how to use Symfony and I can't get the dump() function to work properly. I followed the instruction at : https://symfony.com/doc/current/components/var_dumper.html

I installed the VarDumper component and the Debug Bundle using composer :

composer require --dev symfony/debug-bundle
composer require --dev symfony/var-dumper

Then I used dump() in my app controller in order to show the HTTP request when I submit a form :

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;

 class BlogController extends AbstractController
{
    /**
     * @Route("/blog/new", name="blog_create")
     */
    public function blog_create(Request $request): Response
    {
        dump($request);
        return $this->render('blog/create.html.twig',['request'=>$request]);
    }
}

The dump() should appear in the debug tool bar. Instead, when I call 'blog/new', I just have the normal display of the form page and my debug toolbar doesn't show. However, I know that the VarDumper component works because I tried to use the dump server and the console shows me the result of the dump each time I call 'blog/new'. I am able to find the content of my form in this dump.

Does someone have an idea on how to show the result of dump() inside the debug toolbar and without breaking it ?

Regards,

myst

2
I dont think its a good idea to dump the request...It can be huge. What exactly are yout rying to dump? Any specific var?JureW
The toolbar will only show when you have a reasonably valid html page. Use ctrl-u in your browser and verify have have the expected html head body sections. And of course you have to be in development mode. I am also assuming you are using the actual Symfony framework and not just some of the components. Finally, unless you plan on supporting legacy platforms then there is not reason to be using 4.2. 4.4 is the long term support version.Cerad
@Cerad The html is valid, the toolbar crashes only when I add the line dump($request); I was using "symfony -V" to get the version and the output was "Symfony CLI version v4.21.0 (2020-11-26T16:18:20+0000 - stable)". When I use "php bin/console --version", I get "Symfony 5.1.8 (env: dev, debug: true)". So I assume everything is in order. What do you think ?myst
So 5.1 is the actual framework version which means you are using the latest version. I assume you are also using 'symfony server:start' as your development server? I made a quick test and had no problem with dumping $request. Maybe try not passing $request to your twig template. No reason that I can think of to be doing that anyways.Cerad
Still not working. Any variables passed to dump make the toolbar crash. :/ I'm not sure I did everything right, everything is new to me. I used the symfony server:start as my development server, yes.myst

2 Answers

1
votes

Have you add var-dumper component to your project ?

composer require --dev symfony/var-dumper

Make sure symfony debug bundle is installed:

composer require --dev symfony/debug-bundle

You can dump(...) without this component but the dump will be shown on the top of the page and not on the toolbar.

If you install the component, the dump will display in the toolbar and you will able to use {% dump(myVar) %} in your Twig templates.

0
votes

I persume your request is a POST, as you are creating new blog entry. You should than try with this:

$content = $request->getContent();

Which will now have the bodyof your request, or eventually try:

$content = $request->request->all();

Which will have all that was passed in. Try dumping this values.