Zend headtitle with zend_navigation

I use zend_navigation to create a menu. Which works well. Now I see if I can take the current page and set it as the page title using headTitle. Is there any way to do this?

or

How can I use configuration files (.ini) to create pagetitle and metadata?

+3
source share
1 answer

In the controller, you can get the current active page and get its shortcut. Then you can specify it as the page title.

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

You can also write your own plugin to do this for you in each request:

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);
    }
}
+7
source

Source: https://habr.com/ru/post/1763943/


All Articles