Невозможно отобразить headTitle в представлении макета - PullRequest
1 голос
/ 09 ноября 2011

Мой headTitle запущен, но я не могу отобразить его в файле макета, так как он мне нужен для заголовка страницы.

Вот как я это сделал:

Bootstrap.php:

protected function _initDefaultHelpers() {
    $this->bootstrap('view');
    $view = $this->getResource('view');

    $view->headTitle('Awesome Website');
    $view->headTitle()->setSeparator(' - ');

Мой контроллер:

public function indexAction() {
    $this->_helper->layout()->getView()->headTitle('IndexPage');        
}

Когда я открываю индекс, я получаю: Awesome Website - IndexPage, что идеально.

Но в моем master.phtml, где я использую:

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

абсолютно ничего не дает. На данный момент мне нужен только заголовок «IndexPage», а не весь заголовок, так что это также необходимо учитывать.

Заранее спасибо.

1 Ответ

1 голос
/ 09 ноября 2011

эта работа: протестирована мной локально после создания нового проекта с помощью инструмента Zend!

// application.ini

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Foo"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0

; layout stuff
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"

; view stuff
resources.view[] = ""

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

// в Bootstrap.php

protected function _initDefaultHelpers() {
    $this->bootstrap('view');
    $view = $this->getResource('view');

    $view->headTitle('Foo');
    $view->headTitle()->setSeparator(' :: ');
    $view->doctype("XHTML1_STRICT");
}

// в layout.phtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="it" xml:lang="it">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <?=$this->headTitle()?>

</head>
<body>
    <?=$this->pageTitle?>
    <?=$this->layout()->content?>

</body>
</html>

// в поле зрения

<? $this->pageTitle("Bar"); ?>

// создать представление / помощник / PageTitle.php

<?
class Zend_View_Helper_PageTitle extends Zend_View_Helper_Abstract
{
    public function pageTitle($title)
    {
        $this->view->headTitle($title);
        $this->view->pageTitle = '<h1>' . $title . '</h1>';
    }
}

После этого название вашей страницы будет: Foo :: Bar

...