1

ページヘッダーに必要なため、レイアウトファイルにエコーできないことを除いて、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');        
}

インデックスを開くと、次のようになります。素晴らしいWebサイト-IndexPage、これは完璧です。

しかし、私が使用する私のmaster.phtmlでは:

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

絶対に何も与えません。この時点では、タイトル全体ではなく「IndexPage」というタイトルのみが必要なので、これも考慮する必要があります。

前もって感謝します。

4

1 に答える 1

1

この作業: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"); ?>

// view / helper/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

于 2011-11-09T14:02:19.043 に答える