Zend_Session:必须在任何输出发送到浏览器之前启动会话 [英] Zend_Session: Session must be started before any output has been sent to the browser
问题描述
我以前遇到过这个问题,但我不记得如何解决它.我已经创建了一个简单的骨架(不能再简单了)控制器,我只是想向浏览器回显一些东西,我收到了这条消息:
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();
}
}
}
推荐答案
出于某种原因,我试图在应用程序完成引导后在我的 index.php
文件中设置一些会话变量.不知道为什么这之前没有引起问题,但是当我从我的 index.php
中删除它时,它起作用了.
For some reason, I was trying to set some session variable in my index.php
file after the application had finished bootstrapping. Not sure why this didn't cause a problem before, but when I removed this from my index.php
, it worked.
$userSession = new Zend_Session_Namespace('Auth');
$userSession->forcePasswordChange = false;
这篇关于Zend_Session:必须在任何输出发送到浏览器之前启动会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!