zend headtitle使用zend_navigation

Pra*_*pta 3 php zend-framework zend-navigation

我正在使用zend_navigation来创建菜单.哪个工作正常.现在我正在寻找我是否可以使用headTitle获取当前页面并将其设置为页面标题.有没有办法做到这一点?

要么

我如何使用配置文件(.ini)来创建Pagetitle和元数据?

Dai*_*mon 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);
Run Code Online (Sandbox Code Playgroud)

您还可以编写自定义插件,以便在每个请求中为您执行此操作:

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);
    }
}
Run Code Online (Sandbox Code Playgroud)