Answer the question
In order to leave comments, you need to log in
How to solve an error when outputting any data through the echo or print_r command in the controller?
Greetings. Help me solve the problem, when trying to output something through the echo or print_r command, the following error occurs:
"Failed to start the session because headers have already been sent by "/home/t/torick/sparwindows.gistol.ru/src/AppBundle/ Controller/SparwindowsController.php"at line 40."
<?php
namespace AppBundle\Controller;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
class SparwindowsController extends FrontendController {
public function homeAction() {
echo $a = 1;
$List_array_products = new DataObject\Product\Listing();
$List_array_products->setOrderKey("baseprice");
$List_array_products->setOrder("ASC");
$List_array_products->load();
$this->view->products = $List_array_products;
}
}
Answer the question
In order to leave comments, you need to log in
Don't use echo and print_r, use dump() . The result will not be in the response html, but in the debugger console (panel at the bottom of the page).
If you strongly need to use exactly echo, then you can use output buffering (most likely, you can simply put ob_start()
echo before the output).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question