Evening all

I am working my way through Zend Framework 1.x, and seem to have an issue.

I am trying to set the doctype() to HTML5:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

    protected function __initDoctype() {
        $this->bootstrap('view');
        $view = $this->getResources('view');
        $view->doctype('HTML5');
    }

}

I have check the documentation and using doctype('HTML5') seems to be correct, but my output keeps showing others.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Member Avatar for LastMitch

I have check the documentation and using doctype('HTML5') seems to be correct, but my output keeps showing others.

If you already created the function what is the output?

Take a look at this:

http://framework.zend.com/manual/2.0/en/modules/zend.view.helpers.doctype.html

Did you put this on the page that you want the doctype('HTML5'):

<?php echo $this->doctype() ?>

@LastMitch,

I have doctype() echo'd:

<?php echo $this->doctype(); ?>
<html>
    <head>

This is the first 3 lines of the layout.phtml

Member Avatar for LastMitch

This is the first 3 lines of the layout.phtml

Since you already initial initDoctype()

Instead of this:

<?php echo $this->doctype(); ?>

Try this:

<?php echo $doctype = $view->doctype()->getDoctype(); ?>

I forgot to mention this did you include the $doctypeHelper?

$doctypeHelper = new Zend\View\Helper\Doctype();
$doctypeHelper->doctype('HTML');

<?php echo $this->doctype() ?>

Hi LastMitch,

I tried

    <?php echo $doctype = $view->doctype()->getDoctype(); ?>

but got errors stating :

Notice: Undefined variable: view in C:\xampp\htdocs\thenextsocial\application\layouts\scripts\layout.phtml on line 1

Fatal error: Call to a member function doctype() on a non-object in C:\xampp\htdocs\thenextsocial\application\layouts\scripts\layout.phtml on line 1

Where is the doctypeHelper added? Is this to the Bootstrap function __initDoctype()?

Member Avatar for LastMitch

Where is the doctypeHelper added? Is this to the Bootstrap function __initDoctype()?

Undefined variable: $doctype isn't define. I thought you have doctypeHelper function.

Read this:

https://github.com/zendframework/zf2/blob/master/library/Zend/Form/View/Helper/AbstractHelper.php

There's a few code in the file from the link you need to include for your Bootstrap function you can look at code and read the comment.

I just copy and paste a few of code from the link:

    protected $doctypeHelper;

    public function setDoctype($doctype)
    {
        $this->getDoctypeHelper()->setDoctype($doctype);
        return $this;
    }

    public function getDoctype()
    {
        return $this->getDoctypeHelper()->getDoctype();
    }


protected function getDoctypeHelper()
    {
    if ($this->doctypeHelper) {
        return $this->doctypeHelper;
    }

    if (method_exists($this->view, 'plugin')) {
        $this->doctypeHelper = $this->view->plugin('doctype');
    }

    if (!$this->doctypeHelper instanceof Doctype) {
        $this->doctypeHelper = new Doctype();
    }

    return $this->doctypeHelper;
 }


class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

protected function __initDoctype() {

$doctypeHelper = new Zend\View\Helper\Doctype();
$doctypeHelper->doctype('HTML5');

$this->bootstrap('view');
$view = $this->getResources('view');
$view->doctype('HTML5');

}
}

Something like that.

Ok, i feel stupid.

I had:

protected function __initDoctype()
    {
        $this->bootstrap('view');

SHould be:

protected function _initDoctype()
    {
        $this->bootstrap('view');

Note the single _.

@LastMitch,

The link you put unfortunatley is relating to ZF2, i havent ventured on to that as yet.

But thank you for your input. I have seen HELPERS in ZF1 but not got to those, as i am going through a few tutorials and piecing bits together.

commented: Nice Catch! +11
Member Avatar for LastMitch

Ok, i feel stupid.

Wow, an extra underscore. How can I missed that! =)

I'm glad you figure it out!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.