.I got this kind of error using flash messages in symfony

here is the error:
Failed to start the session because headers have already been sent by "/var/www/project/vendor/symfony/var-dumper/Dumper/AbstractDumper.php" at line 176.

I leave here my template and my controller:

public function create(Request $request)
        $post = new Post();
        $form = $this->createForm(PostType::class, $post);

        if ($form->isSubmitted()) {
            //entity manager
            $em = $this->getDoctrine()->getManager();

            $this->addFlash('success', 'Article Created');

            // $request->getSession()->getFlashBag()->add();
            return $this->redirect($this->generateUrl('post.index'));

here the template:

{% for message in app.flashes('success') %}
    <div class="alert alert-success" >
      {{ message }}
{% endfor %}

I already checked my "/var/www/project/vendor/symfony/var-dumper/Dumper/AbstractDumper.php" at line 176 and this is what i found:

protected function echoLine(string $line, int $depth, string $indentPad)
        if (-1 !== $depth) {
            fwrite($this->outputStream, str_repeat($indentPad, $depth).$line."n");

I try to get what this code has to do with headers or what i can change here but i need help.
thanks in advance

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *