Sevengames Xoom Sevengames Xoom - 1 year ago 74
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download