How-to: Use Html 4.01 in CakePHP 1.2

Posted by Felix Geisendörfer, on Feb 21, 2007 - in PHP & CakePHP » Views & Helpers

Deprecated post

The authors of this post have marked it as deprecated. This means the information displayed is most likely outdated, inaccurate, boring or a combination of all three.

Policy: We never delete deprecated posts, but they are not listed in our categories or show up in the search anymore.

Comments: You can continue to leave comments on this post, but please consult Google or our search first if you want to get an answer ; ).

Hi folks,

this is just a little tip for those of you who dislike their xhtml to end up as tag soup and still prefer to send out Html 4.01 strict. Here is how to make all helper functions in Cake 1.2 output Html 4.01 compliant markup instead of xhtml:

php
  1. class AppHelper extends Helper
  2. {
  3.     /**
  4.      * This is the constructor for our AppHelper class that we use to make all helper output html 4.01
  5.      * compatible markup.
  6.      *
  7.      * @return AppHelper
  8.      */
  9.     function __construct()
  10.     {
  11.         // Loop through all tags in this helper
  12.         foreach ($this->tags as $tag => $html)
  13.         {
  14.             // Replace all xhtml style tag closings with html 4.01 strict compatible ones
  15.             $this->tags[$tag] = r('/>', '>', $html);
  16.         }
  17.     }
  18. }

If you wonder why somebody would prefer the good old html over the all-so-hyped xhtml, read a little bit about it here.

-- Felix Geisendörfer aka the_undefined