3

メニューの作成に zend_navigation を使用しています。これはうまくいきます。現在のページを取り、headTitle を使用してページ タイトルとして設定できるかどうかを調べています。それを行う方法はありますか?

また

Pagetitle とメタ データを作成するために構成ファイル (.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 に答える