Php – How to fix “Cannot send headers; headers already sent” in Zend?

phpzend-framework

Possible Duplicate:
Headers already sent by 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,

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

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:

<?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

Best Solution

It may be because of extra white spaces after php closing tag (?>) in some file.

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

For example:

enter image description here

Related Question