我的问题是,如何在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
方法,但您必须为此创建一个变通方法。