I have a class:
class Controller{}
and 2 other classes:
class HomeController extends Controller()
{
public function ActionResult_Index()
{
}
}
class AboutController extends Controller()
{
public function ActionResult_Index()
{
}
}
If I call $this->ActionResult_Index(); from within the Controller class, which one will be called? Is there a way of defining?
Take the following example...
class A {
}
class B extends A {
public function boo()
{
return 'B';
}
}
class C extends A {
public function boo()
{
return 'C';
}
}
$a = new A;
$b = new B;
$c = new C;
$a->boo(); // Undefined method
$b->boo(); // B
$c->boo(); // C
Since A
doesn't have a boo()
method you won't get any result (in fact you will just get an error). B
and C
will each fire there own version of the method.
Since HomeController
and AboutController
extends Controller
and HomeController
and AboutController
contains ActionResult_Index
and Controller
does not contains ActionResult_Index
unless you instantiate HomeController
or AboutController
you will not be able to access ActionResult_Index
from Controller
$home = new HomeController;
$home->ActionResult_Index();
In the above the ActionResult_Index method of HomeController is called.
$about = new AboutController;
$about->ActionResult_Index();
In the above the ActionResult_Index method of AboutController is called.
If you have:
$controller = new Controller;
$controller->ActionResult_Index();
You'll get an undefined method error. The controller class doesn't have a method by that name.
If you call $this->ActionResult_Index()
from within the Controller
class, you'll get a fatal error, because the Controller
class doesn't implement that method. Parents don't inherit from their children, it's the other way around.
Also: your extends
syntax is wrong; get rid of the ()
after the name of the base class.