0

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">
2
Contributors
7
Replies
23
Views
4 Years
Discussion Span
Last Post by LastMitch
0

@LastMitch,

I have doctype() echo'd:

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

This is the first 3 lines of the layout.phtml

0

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() ?>

Edited by LastMitch: grammer

0

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()?

1

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.

1

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.

Votes + Comments
Nice Catch!
0

Ok, i feel stupid.

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

I'm glad you figure it out!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.