Zend_Session: Session must be started before any o

2019-02-25 01:08发布

I've run into this issue before, but I can't remember how to solve it. I have created a bare bones (can't get any simpler) controller, and am just trying to echo something to the browser, and I am getting 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's my entire controller. It's displaying 'success', but it also displays the error message. How can I silence that error message so I can simply echo something to 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();
        }
    }
}

7条回答
我欲成王,谁敢阻挡
2楼-- · 2019-02-25 02:01

I encountered same problem and my issue was that I was echoing a STRICT warning that was being put to the screen.

A good way to debug this is issue is the use ob_start() and ob_get_contents();

Hope it helps

查看更多
登录 后发表回答