Php 使用zend_导航的zend headtitle

Php 使用zend_导航的zend headtitle,php,zend-framework,zend-navigation,Php,Zend Framework,Zend Navigation,我正在使用zend_导航创建菜单。这很好用。现在我正在寻找是否可以使用headTitle将当前页面设置为页面标题。有没有办法做到这一点 或 如何使用配置文件(.ini)创建页面标题和元数据 在控制器中,您可以获取当前活动页面并获取其标签。然后将其设置为页面标题 //get active page and its label $activePage = $this->view->navigation()->findOneBy('active', true); $label = $

我正在使用zend_导航创建菜单。这很好用。现在我正在寻找是否可以使用headTitle将当前页面设置为页面标题。有没有办法做到这一点


如何使用配置文件(.ini)创建页面标题和元数据

在控制器中,您可以获取当前活动页面并获取其标签。然后将其设置为页面标题

//get active page and its label
$activePage = $this->view->navigation()->findOneBy('active', true);
$label = $activePage->get('label');

//set page label as html title
$this->view->headTitle($label);
您还可以编写自定义插件,在每个请求中为您执行此操作:

class Plugin_NavigationTitle extends Zend_Controller_Plugin_Abstract
{
    function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        //get view
        $view = Zend_Controller_Action_HelperBroker::getExistingHelper('ViewRenderer')->view;

        //get active page and its label
        $activePage = $view->navigation()->findOneBy('active', true);
        $label = $activePage->get('label');

        //set page label as html title
        $view->headTitle($label);
    }
}

回答得又好又正确。不知道@JapanPro为什么不接受它。