0

Hey gang,

I am trying to get my site running using the MVC approach.

I have a parent class called BaseController. All other contoller classes inherit from it.

When you go to http://example.com/home/index the HomeComtroller loads properly (a child of BaseController).

Where I am stuck is having HomeController executing its methods.
The URL set up is ?controller=nameofclass&action=nameofmethod&id=someidgoeshere, with mod_rewrite handling the URL.

I use $_GET to identify the method to be executed, by calling $this->action(); which in theory should automatically execute a method with the corresponding name. And it works -- only thing is, it is looking for a method inside the parent class instead of the child class to execute.

Is there a way to pass the $this->action() to my child class and have the child class execute the specified method?

I do have all of this in the parent constructor, but even when I call this->action() from a child class, it still searches the parent class for the method.

Thank you for your time!

1
Contributor
1
Reply
13
Views
3 Years
Discussion Span
Last Post by Andrew_7
0

Okay, got it figured out.

I had to change $this->action() to $this->$action().

So it runs great!

Now, only question left is, how can I instantiate the child class from inside the parent class, that way I don't have to declare new SomeController every time I create a new controller class?

Thanks for any ideas!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.