3

我正在使用 zend_navigation 创建菜单。哪个工作正常。现在我正在寻找是否可以获取当前页面并使用 headTitle 将其设置为页面标题。有什么办法吗?

或者

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

4

1 回答 1

7

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

//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);
    }
}
于 2010-11-08T13:49:11.200 回答