Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Actually, <code>index.php</code> should not contain any meaningful code at all, since it would be only part of your site, that is located inside <code>DOCUMENT_ROOT</code> of webserver. It's content should actually look something like:</p> <pre><code>&lt;?php require '../application/bootstrap.php'; </code></pre> <p>It should only include a file outside <code>DOCUMENT_ROOT</code>. And that's all.</p> <p>This way, if something goes horribly wrong (like, php extension fails after server update) and visitors are exposed to raw php code, it will not reveal any sensitive details.</p> <p>The point of <a href="http://martinfowler.com/eaaCatalog/frontController.html"><em>Front Controller</em></a> is handle all user input, turn it into a <em>consumable</em> form and, based on it, dispatch a command (usually in a form of method call on an object). In languages like Java, where everything must be contained in a class, a front controller would be a class. But in php you do not have this restriction.</p> <p>Instead the <em>front controller</em> will end up being part of your bootstrap stage of the application:</p> <pre><code>// --- snip --- // the autoloader has been initialized already a bit earlier $router = new Router; $router-&gt;loadConfig($configuration); $request = new Request; $request-&gt;setUri($GET['url']); // could also be $_SERVER['PATH_INFO'] or other // depends on how url rewrite is set up $router-&gt;route($request); // the request instance is populated with data from first matching route $class = $request-&gt;getParameter('resource'); $command = $request-&gt;getMethod() . $request-&gt;getParameter('action'); if (class_exists($class)) { $instance = new $class; $instance-&gt;{$command}($request); // you dispatch to the proper class's method } // --- snip --- // then there will be some other code, unrelated to front controller </code></pre> <p>Also, you should keep in mind that concept of <em>front controller</em> is neither made-for nor demanded-by application that attempt to implement MVC or MVC-inspired architecture.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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