You must put it in your bootstrap file.
Here's how you can do it:
- Configure each HTTP request to your front controller, index.php, app.php or whatever you want to call it.
- Front Controller can define some constants used in the framework and then include your Bootstrap.php file. Bootstrap will load your application.
- Now the first thing I do in Bootstrap is to register autoload. That way, I can easily get the class \ System \ Router \ Router or \ System \ Router \ Dispatcher, you get the point.
One more thing: you can even register the Application Models folder with the PSR0 class loader. So let's say that the Models folder looks like this:
application/Models/ - Entities - Services Email.php Cache.php
From inside your controller, you can easily get Models like this
public function someController() { $email = new \Models\Services\Email();
So, the short answer to your question is that it is best to have the first front controller, which gives you some kind of "wiggle" room, and then from there you download your Bootstrap, which loads your application, and, first of all, in Bootstrap requires your classloader and register library, which you want to use through the application.
And then you can even register autoload for your folder “Controllers and application models”, and at the end of the Bootstrap file, when you are going to send a request, you can request the controller as follows:
$app = new '\\Application\\Controllers\\' . $class; // Dispatch request with call_user_func_array or ReflectionMethod and ReflectionClass
You do not need to require a controller class from the time it is started, just specify the correct namespace for it.
Great question, hope this helps! It's nice to see that there are other guys who play with their Custome MVC :)
source share