myst
myst

Reputation: 21

Can't make dump() work in Symfony 4.2 toolbar

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

Upvotes: 2

Views: 2509

Answers (2)

SwissLoop
SwissLoop

Reputation: 499

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.

Upvotes: 4

JureW
JureW

Reputation: 683

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.

Upvotes: 0

Related Questions