Zend_Session: the session must be started before any output is sent to the browser

I have already encountered this problem, but I can’t remember how to solve it. I created a simple (I can’t get a simpler) controller and just try to repeat something in the browser, and I get this message:

Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'Session must be started before any output has been sent to the browser ...

Here is my one-piece controller. It displays "success" but also displays an error message. How to disable this error message so that I can just repeat something in the browser?

<?php

class CacheController extends Zend_Controller_Action
{
    public function clearAction()
    {
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender();
        try {
            $result = Model_Cache::emptyCache(array('foobar'=>1));

            if ($result['status'] == true) {
                echo 'Success';
            } else {
                echo 'Error: ' . $result['message'];
            }
        } catch (Exception $e) {
            echo 'Error: ' . $e->getMessage();
        }
    }
}
+3
source share
7 answers

- index.php , . , , index.php, .

$userSession = new Zend_Session_Namespace('Auth');
$userSession->forcePasswordChange = false;
+1

- -PHP-, ( ). - ?>. , .

+6

, , Zend_Session . - , , Zend_Session.

protected function _initSessions()
{
    Zend_Session::start();
}

Zend Framework. , PHP-, -.

, !

+4

:

PHPUnit, Zend_Session

, , , , , Zend_Session

 /**
 * Whether or not Zend_Session is being used with unit tests
 *
 * @internal
 * @var bool
 */
public static $_unitTestEnabled = false;

"true", phpunit - . , , .

+2

, , STRICT, .

ob_start() ob_get_contents();

,

+1

, application.ini php.ini( )? ide, "".

"" ( ) .

0

. . :

$customersModel = new Default_Model_DbTable_Customers();
$this->view->customers = $customersModel->fetchAll();

6000 . .

0

Source: https://habr.com/ru/post/1769436/


All Articles