我需要做的是延長getPageTitle()
功能,使標題被翻譯和action
和controller
交換 這是我放在Controller.php這樣Yii的擴展控制器功能
private $_pageTitle;
public function getPageTitle()
{
if($this->_pageTitle!==null) {
return Yii::t('wm', $this->_pageTitle);
} else {
$controller = Yii::t('wm', ucfirst(basename($this->getId())));
if($this->getAction()!==null && strcasecmp($this->getAction()->getId(),$this->defaultAction)) {
$action = Yii::t('wm', ucfirst($this->getAction()->getId()));
return $this->_pageTitle=Yii::app()->name.' - '.Yii::t('wm', '{action} {controller}', array('{action}' => $action, '{controller}' => $controller));
} else {
return $this->_pageTitle=Yii::app()->name.' - '.$controller;
}
}
}
但如果在視圖中我設置一個新的自定義標題與這些
$this->pageTitle = 'Title';
$this->setPageTitle('Title2');
Yii::app()->getController()->pageTitle="Title3";
什麼
標題沒有得到改變
如果我檢查parent::getPageTitle()
,它總是返回值
如果我檢查$this->_pageTitle
它總是返回null