php - Zend_Session : Session must be started before any output has been sent to the browser

标签 php zend-framework zend-session

我以前遇到过这个问题,但我不记得如何解决它。我已经创建了一个基本的(再简单不过了) Controller ,我只是想向浏览器回显一些东西,我收到了这条消息:

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

这是我的整个 Controller 。它显示“成功”,但也显示错误消息。我怎样才能使该错误消息静音,以便我可以简单地向浏览器回显一些内容?

<?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();
        }
    }
}

最佳答案

根据内存,此错误通常是由于非 PHP 代码在预期(和 session 初始化)之前开始输出。通常是由于不必要的 ?> 标签后出现空格或回车。这是我要检查的第一件事。

关于php - Zend_Session : Session must be started before any output has been sent to the browser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3928597/

相关文章:

php - 从数据库获取数据时数组的问题

javascript - 带有 AJAX、PHP、HTML 的 UTF-8 '?' 符号

php - 通过命令行运行 php 脚本时如何加载 Zend 类

php - 复合元素不起作用

zend-framework - Zend session 和 Zend 身份验证

php - 管理/员工面板的简单实现?

php - 如何使用 jQuery 每 1 秒从数据库获取实时数据

php - 全页缓存, block 更新

php - Zend Auth 锁定 session

php - Zend Framework MVC 重定向到不同的 Controller 和操作