Получение ошибки в Linux-системе с Nginx/PHP-FPM с сообщением «Не удалось запустить сеанс, поскольку заголовки уже отправлены». Ошибка не возникает при настройке локального компьютера Apache
Итак, на моем локальном компьютере приложение Symfony2 работает нормально. Никаких ошибок не выскакивает. Но как только я развертываю наш Linux-сервер, я получаю эту ошибку при вызове определенного действия в классе контроллера
Код: Выделить всё
Failed to start the session because headers have already been sent.
Код: Выделить всё
$session = $this->getRequest()->getSession();
Код: Выделить всё
$session->set('foo', $bar);
Код: Выделить всё
.... some fields here .....
Вот объявление контроллера, indexAction() и мой 2ndAction()
Код: Выделить всё
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use CBSi\Utils\HTTPUtils\CURLUtil;
class StartController extends Controller
{
/**
* @var CurlUtil $curlUtil
*/
private $curlUtil;
/**
* @var AccessControl $accessControl
*/
private $accessControl;
/*placeholder for request object*/
private $requestHolder;
/**
* @Route("/path/for/action/one", name="start")
* @Template()
*/
public function indexAction()
{
$session = $this->getRequest()->getSession();
$this->curlUtil = $this->get('curlUtil');
$this->requestHolder= Request::createFromGlobals();
// Some logic is done here
return $this->render('ListEngagementBundle:Start:start.html.twig');
}
/**
* @Route("/path/to/second/action", name="2ndAction")
* @Template
*/
public function 2ndAction(){
$session = $this->getRequest()->getSession();
$this-> curlUtil = $this->get('curlUtil');
$this->requestHolder= Request::createFromGlobals();
//Some logic is done here to get the data for the session variable
$bar= logic output
$session->set('foo', $bar);
return $this->redirect($this->generateUrl('start'));
}
}
Подробнее здесь: https://stackoverflow.com/questions/131 ... -been-sent
Мобильная версия