简体   繁体   中英

zend headtitle using zend_navigation

I am using zend_navigation for creating menu. Which works fine. Now im looking if i can take current page and set it as page title using headTitle. Is there is any way to do that?

or

how can i use config files (.ini) for creating Pagetitle and meta data ?

In controller you can get current active page and get its's label. Then you cen set it as 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 could also write custom plugin to do it for you in every 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);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM