无法在布局视图中回显 headTitle

发布于 2024-12-14 14:49:45 字数 720 浏览 3 评论 0原文

我的 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”而不是整个标题,所以这也必须考虑。

提前致谢。

I got my headTitle up running, except i cannot echo it in my layout file as i need it for page header.

This is how i done it:

Bootstrap.php:

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

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

My Controller:

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

When i open index i get: Awesome Website - IndexPage, which is perfect.

But in my master.phtml where i use:

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

Gives absolutely nothing. At this point i only want the title "IndexPage" and not the entire title, so this also has to be considered.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许仙没带伞 2024-12-21 14:49:45

这项工作:使用 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

//into Bootstrap.php

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

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

//into 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>

//into view

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

//create 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

this work: tested by me locally after creating a new project with zend tool!

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

//into Bootstrap.php

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

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

//into 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>

//into view

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

//create 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>';
    }
}

After that the name of your page will be: Foo :: Bar

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文