Sevengames Xoom Sevengames Xoom - 6 months ago 26
PHP Question

How to call the index function inside a class when a file is load?

I'm wondering how I can call the index function inside the class

, an example:

the user put this URL in the browser:

the file
contain this:


Class App{

public function index()
// do stuff..

I want that when this file is opened in the browser, the index function must be executed automatically... How can I achieve that?


You can call index on an instance of App.

$app = new App();

However, it feels like there is something missing here. Typically you would have a router that would handle instantiating the correct controller based on the route requested by the user.

You can use the above code to manually instantiate the app controller and call index, but again, I think there is a missing piece.