[英]Yii controller inheritance ( in submodule )
我的問題是,如何在YII中繼承Controllers動作,例如:
class MainController extends FController
{
public function ActionIndex()
{
$this->render("index"); //the view;
}
}
--------------------------------------------
class SecondController extends FController
{
public function ActiondIndex()
{
MainController::ActionIndex();
}
}
實際上,在我的情況下,SecondController是子模塊的DefaultController。 我想制作基於單個代碼的網頁。
由於PHP不支持多重繼承,因此您可以通過parent關鍵字訪問基類。
class MainController extends FController
{
public function ActionIndex()
{
$this->render("index"); //the view;
}
}
class SecondController extends FController
{
public function ActionIndex() // Note: you mistyped the name of this action in your example
{
parent::ActionIndex();
}
}
盡管您無法直接訪問祖父母的ActionIndex
方法,但您必須為此創建解決方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.