Setting the doctype in Zend Framework 2

I recently had to change the doctype in a Zend Framework 2 environment. It was kind of difficult to find the answer so I share with you. Simply set the doctype before “running it” in index.php like this:

<?php
/**
 * This makes our life easier when dealing with paths. Everything is relative
 * to the application root now.
 */
chdir(dirname(__DIR__));

// Setup autoloading
include 'init_autoloader.php';

$doctypeHelper = new ZendViewHelperDoctype();
$doctypeHelper->setDoctype($doctypeHelper::HTML5);

// Run the application!
ZendMvcApplication::init(include 'config/application.config.php')->run();

The possible doctypes are:

XHTML11            
XHTML1_STRICT      
XHTML1_TRANSITIONAL
XHTML1_FRAMESET    
XHTML1_RDFA        
XHTML1_RDFA11      
XHTML_BASIC1       
XHTML5             
HTML4_STRICT       
HTML4_LOOSE        
HTML4_FRAMESET     
HTML5              
CUSTOM_XHTML       
CUSTOM

That’s all folks.

One thought on “Setting the doctype in Zend Framework 2”

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.