Skip to end of metadata
Go to start of metadata

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

Zend Framework: Zend_Controller_Action Component Proposal

Proposed Component Name Zend_Controller_Action
Developer Notes http://framework.zend.com/wiki/display/ZFDEV/Zend_Controller_Action
Proposers My E-mail Address
Revision 1.1 - 18 July 2006 - First revision (wiki revision: 6)

Table of Contents

1. Overview

This is a simple suggestion for a modification to the _redirect member of Zend_Controller_Action.

I was attempting to write a simple logout procedure for some test code, and found that the logout redirect that used _redirect within a class, was failing with no evident output to redirect due to 'Headers already sent'

In the end it was whitespace at the end of my LogoutController that was causing the issue. However, the way I found it
was that using the PHP5 function headers_sent, I modified the code inside the library for Zend_Controller_Action to use the optional $file and $line variables to find where the header issue was being caused.

Perhaps this is something you might want to use in the _redirect function, since the output it gives upon failure can be used to help troubleshoot a very simple error which can plague the unwary coder for a fair while before discovering the issue, especially if the whitespace is hiding after the closing ?> tag in a Controller file as in my case.

2. References

zone: Missing {zone-data:references}

3. Component Requirements, Constraints, and Acceptance Criteria

zone: Missing {zone-data:requirements}

4. Dependencies on Other Framework Components

zone: Missing {zone-data:dependencies}

5. Theory of Operation

zone: Missing {zone-data:operation}

6. Milestones / Tasks

zone: Missing {zone-data:milestones}

7. Class Index

  • Zend_Controller_Action

8. Use Cases

zone: Missing {zone-data:use-cases}

9. Class Skeletons

zone: Missing {zone-data:skeletons}
]]></ac:plain-text-body></ac:macro>

]]></ac:plain-text-body></ac:macro>

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Sep 20, 2006

    <p>You could make _redirect() more robust to headers already sent issues by augmenting it to do something like:</p>

    <p>replace:</p>
    <ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
    if (headers_sent()) {
    throw new Zend_Controller_Action_Exception('Cannot redirect because headers have already been sent.');
    }
    ]]></ac:plain-text-body></ac:macro>
    <p>with</p>
    <ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
    if (headers_sent()) {
    echo <<<EOT
    <script type="text/javascript"><!--
    location.replace("$url");
    //--></script>
    <noscript><meta http-equiv="Refresh" content="0;url=$url"></noscript>
    EOT;
    return;
    }
    ]]></ac:plain-text-body></ac:macro>

    1. Oct 10, 2006

      <p>There are several issues with this approach:</p>

      <ul>
      <li>for browsers without javascript or where JS is turned off, the redirect simply will not happen.</li>
      <li>you can't assume that the document <body> has already been opened</li>
      <li>if you get several of these snippets in place, they act as a FIFO queue, and they're still difficult to debug.</li>
      </ul>

      <p>The OP's proposal is a simple solution that can be implemented quickly, and helps the developer find the root cause of the issue quickly.</p>

  2. Oct 11, 2006

    <ac:macro ac:name="note"><ac:parameter ac:name="title">Zend Comment</ac:parameter><ac:rich-text-body>
    <p>This proposal is accepted and will be implemented by the Zend devteam.</p></ac:rich-text-body></ac:macro>