Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should put it in your bootstrap file.</p> <p>This is how you can do this:</p> <ol> <li>Force every HTTP request to your front controller, index.php, app.php or how ever you want to call it.</li> <li>Front Controller can define some constants used in framework and then include your Bootstrap.php file. Bootstrap will boot up your application.</li> <li>Now, first thing in I do in Bootstrap is to register autoloading. This way I can easily get \System\Router\Router class, or \System\Router\Dispatcher class, you get the point.</li> </ol> <p>One more thing, you can even register your application Models folder with PSR0 class loader. So lets say that your Models folder looks like this:</p> <pre><code>application/Models/ - Entities - Services Email.php Cache.php </code></pre> <p>From inside your controller you can easily get Models like this</p> <pre><code>public function someController() { $email = new \Models\Services\Email(); // Do stuff with email service } </code></pre> <p>So short answer to your question is that the best thing to have is first Front Controller that gives you some "wiggle" room, then from there you load your Bootstrap that boots up your app, and first thing in Bootstrap is to require your class loader, and register libraries you want to use through application. </p> <p>And then you can even register autoloading for your application Controllers and Models folder, and at the end of Bootstrap file when you are about to dispatch request you can ask for Controller like this:</p> <pre><code>$app = new '\\Application\\Controllers\\' . $class; // Dispatch request with call_user_func_array or ReflectionMethod and ReflectionClass </code></pre> <p>No need to require Controller class since its autoloaded, just provide it with correct namespace.</p> <p>Great question, hope this helps! Nice to see there are other guys playing around with their custome MVC :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload