Zend: How to get a view in Bootstrap.php?

I want to set the title of a webpage in Bootstrap. I am doing something similar in Bootstrap.php:

protected function _initViewHelpers() {         
    $view = Zend_Layout::getMvcInstance()->getView();
    $view->headTitle( 'My Title' );
}

I get the following error:

Fatal error: Call to a member function getView() on a non-object in /var/www/student/application/Bootstrap.php on line 7

How can I get an idea? I also tried this .

+3
source share
5 answers

Now it works for me:

In bootstrap.php

protected function _initViewHelpers() {
    $view = new Zend_View();
    $view->headTitle('Main Title')->setSeparator(' - ');
}

In any view /.phtml

<?php 
    $this->headTitle()->prepend('Page Title');
    echo $this->headTitle();
?>
+2
source

@ArneRie is close, but the syntax is incorrect. This is from quickstart :

protected function _initDoctype()
{
    $this->bootstrap('view');
    $view = $this->getResource('view');
    $view->doctype('XHTML1_STRICT');
    // but what you really want is
    $view->headTitle('My title');
}
+6
source

, .

protected function _initViewHelpers() {
    $view = Zend_Layout::startMvc()->getView();
    $view->headTitle( 'My Title' );
}

startMVC $options, , Zend_Config, MVC. ZF application.ini. , , .

. . , . Zend_Layout .

+5

:

protected function _initViewHelpers() {         
    $bootstrap = $this->getBootstrap();
    $view = $bootstrap->getResource('view');
    $view->headTitle( 'My Title' );
}
+1
$this->title = "Edit album";
$this->headTitle($this->title);
+1

All Articles