php 如何修复 Zend 中的“无法发送标头;标头已发送”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6420733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fix "Cannot send headers; headers already sent" in Zend?
提问by mymotherland
Possible Duplicate:
Headers already sent by PHP
可能重复:
PHP 已发送的标头
I am new to zend.I tried to create simple form having two fields using zend. When i click submit button got the following error,
我是 zend 的新手。我尝试使用 zend 创建具有两个字段的简单表单。当我点击提交按钮时出现以下错误,
Fatal error: Uncaught exception 'Zend_Controller_Response_Exception' with message 'Cannot send headers; headers already sent in D:\xampp\htdocs\study\quickstart\application\controllers\EmployeeController.php, line 35' in D:\xampp\php\PEAR\Zend\Controller\Response\Abstract.php:282 Stack trace: #0 D:\xampp\php\PEAR\Zend\Controller\Response\Abstract.php(300): Zend_Controller_Response_Abstract->canSendHeaders(true) #1 D:\xampp\php\PEAR\Zend\Controller\Response\Abstract.php(727): Zend_Controller_Response_Abstract->sendHeaders() #2 D:\xampp\php\PEAR\Zend\Controller\Front.php(984): Zend_Controller_Response_Abstract->sendResponse() #3 D:\xampp\php\PEAR\Zend\Application\Bootstrap\Bootstrap.php(77): Zend_Controller_Front->dispatch() #4 D:\xampp\php\PEAR\Zend\Application.php(358): Zend_Application_Bootstrap_Bootstrap->run() #5 D:\xampp\htdocs\study\quickstart\public\index.php(25): Zend_Application->run() #6 {main} thrown in D:\xampp\php\PEAR\Zend\Controller\Response\Abstract.php on line 282
I checked the following link, zend header already send problem
我检查了以下链接, zend header 已经发送问题
I removed white spaces and gave close tag in all files, But still i am getting same error.
我删除了空格并在所有文件中给出了关闭标记,但我仍然遇到相同的错误。
How to fix this error ?
如何修复此错误?
Following shows EmployeeController.php:
以下显示EmployeeController.php:
<?php
class EmployeeController extends Zend_Controller_Action
{
public function init()
{
}
public function indexAction()
{
$form = new Default_Form_Empdetails();
$this->view->form = $form;
$request = $this->getRequest();
$formData = $request->getPost();
if ($request->isPost()) {
if ($form->isValid($request->getPost())) {
$empName = $form->getValue('empName');
$empAddress = $form->getValue('empAddress');
$emp = new Default_Model_DBTable_Employee();
$emp->addAlbum($empName, $empAddress);
$this->_helper->redirector('index');
} else {
$form->populate($formData);
}
}
}
}
?>
Kindly help me
请帮助我
回答by Naveed
It may be because of extra white spaces after php closing tag (?>
) in some file.
这可能是因为?>
某些文件中php 结束标记 ( )后有多余的空格。
Also read this Post:
另请阅读此帖子:
PHP development: why redirects don't work (headers already sent)
- Any HTML output, including the DOCTYPE declaration or any HTML tag, including the head of the page
- Extra whitespace before the opening PHP tag of the page, or outside the PHP tags of an include file
- Using print() or echo before calling header() or session_start()
- Using virtual() to include files
- Using the byte-order mark (BOM) at the beginning of a page
- 任何 HTML 输出,包括 DOCTYPE 声明或任何 HTML 标签,包括页面的头部
- 页面打开 PHP 标记之前或包含文件的 PHP 标记之外的额外空白
- 在调用 header() 或 session_start() 之前使用 print() 或 echo
- 使用 virtual() 包含文件
- 在页面开头使用字节顺序标记 (BOM)
For example:
例如: