<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[
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 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.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
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.2. References
3. Component Requirements, Constraints, and Acceptance Criteria
4. Dependencies on Other Framework Components
5. Theory of Operation
6. Milestones / Tasks
7. Class Index
zone: Missing {zone-data:references}
zone: Missing {zone-data:requirements}
zone: Missing {zone-data:dependencies}
zone: Missing {zone-data:operation}
zone: Missing {zone-data:milestones}
zone: Missing {zone-data:use-cases}
zone: Missing {zone-data:skeletons}
]]></ac:plain-text-body></ac:macro>]]></ac:plain-text-body></ac:macro>
Labels:
None
3 Comments
comments.show.hideSep 20, 2006
Rob Allen
<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>
Oct 10, 2006
Matthew Weier O'Phinney
<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>
Oct 11, 2006
Matthew Weier O'Phinney
<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>