2010-09-09 38 views
3

我正在使用zend_navigation創建菜單。哪些工作正常。現在我正在尋找是否可以將當前頁面設置爲使用headTitle的頁面標題。有沒有辦法做到這一點?zend headtitle using zend_navigation

如何使用配置文件(.INI),用於創建和PAGETITLE元數據?

回答

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

尼斯和正確的答案。不知道爲什麼@JapanPro不接受它。 – 2011-10-12 10:57:30