1

I'm working through the Zend Framework 1.8 Web Development book, and I'm at the part that describes how you can edit the bootstrap.php to initialize a doctype for you. However, when I insert the function, I get a server error when I navigate to my project.

The application only breaks after I add the following code to my Bootstrap.php

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

    protected function _initViewSettings()
    {
        $this->bootstrap('view');
        $view = $this->getResource('view');
        $view->doctype('XHTML1_STRICT');
    }

}
4
  • HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request. And when I take the function out, the page loads my view just fine. Commented Mar 17, 2011 at 23:25
  • Can you narrow it down further, to just one line? Commented Mar 17, 2011 at 23:29
  • It looks to be the last line of the function Commented Mar 17, 2011 at 23:32
  • Hmm maybe it's changed since 1.8. I guess the proper syntax now is $doctypeHelper = new Zend_View_Helper_Doctype(); $doctypeHelper->doctype('XHTML1_STRICT'); Commented Mar 17, 2011 at 23:36

2 Answers 2

4

Matthew's article on this topic made things very clear for me:

http://weierophinney.net/matthew/archives/230-Quick-Start-to-Zend_Application_Bootstrap.html

I recommend reading the whole article as well as the linked manual page:

http://framework.zend.com/manual/en/zend.application.available-resources.html

So if you are initializing the view, you could do something like this:

protected function _initView()
{
    $view = new Zend_View();
    $view->doctype('XHTML1_STRICT');
    // do other stuff to the view...
    return $view;
}

What the others are saying is correct. However, I found the methods described by Matthew and using the application.ini as well to provide the cleanest bootstrap. Please do read the article as it explains dependencies and naming conventions.

It also seems like you do not have your error reporting settings configured to display detailed errors. If you change this, you will see a more concise error, rather than just the general HTTP 500.

Sign up to request clarification or add additional context in comments.

Comments

1

Make sure you have the view resource in your config. Otherwise, there will be no view resource. It's also good to set the view encoding so kill two birds with one stone

resources.view.encoding = "UTF-8"

I have the following in my Bootstrap.php file (ZF 1.11.4) and it works just fine

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

    /* @var $view Zend_View */
    $view = $this->getResource('view');

    $view->doctype(Zend_View_Helper_Doctype::HTML5);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.