DISCLAIMER: OK, I know that browser support for serving XHTML pages as
application/xhtml+xml is not very good yet.
That said, since most of the sites I develop using ZF use the XHTML
strict doctype, I was experimenting with conditionally serving the
pages with the correct mime-type to browsers that claim to support it.
To test, I added this block to the top of index.php:
<?php
header("Vary: Accept");
if (stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml"))
header("Content-Type: application/xhtml+xml; charset=utf-8");
else
header("Content-Type: text/html; charset=utf-8");
// rest of index.php ...
?>
I encountered a couple issues that convinced me rather quickly to
revert to the default (serving all requests as text/html):
1) The contents of the HeadStyle view helper are not "properly"
escaped for XHTML. I'm not sure it can be, though, as this could
create compatibility issues with other browsers that can otherwise
display the pages OK. Simplest solution - move the style declarations
to an external document and link it with HeadLink instead. Still, I
wonder if it would be possible to have the HeadStyle view helper check
HTTP_ACCEPT as above and, if supported by the browser, change the way
it marks up the <style> tag. (I believe the markup used for inline
Javascript worked OK.)
2) Zend_Form (and perhaps other helpers or decorators) sometimes
insert the HTML entity ' ' for non-breaking spaces (such as
between <dt>...</dt> tags in the DtDdWrapper decorator), but that
entity is not valid in XHTML. Because of this, the page doesn't even
validate in Firefox and is therefore rendered as a yellow page with an
XML Parsing Error. There may also be similar issues that result from
character escaping in Zend_View since characters like 'é' could be
escaped as 'é' rather than '&#E9;'.
I know this isn't much of a priority until browser support improves,
but in the interest of being forward-thinking and moving toward
"correctness" is it possible to serve valid pages with the correct
XHTML mime-type using ZF or is this still too much of a mine field?
Andrew