Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, you need to redirect all your requests to a single PHP file. That part you do in <em>.htaccess</em> on Apache or it's counterparts on other servers.</p> <p>Then you need to explore what data you can see in <code>$_SERVER</code>. It's quite common to use <code>$_SERVER['PATH_INFO']</code>, but the choice will depend on how exactly you rewrite the request.</p> <p>Then you need to create a router, that has a list of regular expression and tries to match then against the URL fragment that you have acquired.</p> <p>Here are few example that might give you some ideas:</p> <ul> <li><code>'#^/(?P&lt;page&gt;[^/\\\\.,;?\n]+)$#'</code></li> <li><code>'#^/user/(?P&lt;id&gt;[0-9]+)/(?P&lt;nickname&gt;[^/\.,;?\n]+)$#'</code></li> <li><code>'#^(?:/test/(?P&lt;parameter&gt;[^/\\\\.,;?\n]+))?/mandatory$#'</code></li> </ul> <p>It is common practice tho have these regular expressions generated from much simpler notations, but for the first iteration you should not focus on it too much.</p> <p>Also, if you use expressions, that have optional fragments, you should also provide "fallback" values. These values would be used as defaults, if fragment is not provided, but pattern is matched.</p> <p>The way I do it all looks like this in PHP:</p> <pre><code>/* * Routing mechanism */ $uri = isset( $_SERVER[ 'PATH_INFO' ] ) ? $_SERVER[ 'PATH_INFO' ] : '/'; $builder = new RequestBuilder; $request = $builder-&gt;create(); $request-&gt;setUri( $uri ); $router = new Router( new RouteBuilder ); $router-&gt;import( $reader-&gt;getAsArray( __DIR__ . '/config/routes.json' ) ); $router-&gt;route( $request ); </code></pre> <p>After this the <code>$request</code> variable contains an object, which then you can query for specific parameter using commands like <code>$id = $request-&gt;getParameter('id')</code> or <code>$controller = $request-&gt;getParameter('controller')</code>.</p> <p>If you do not mess up with patterns themselves, then the values, that you extract will be safe against unauthorized file inclusions.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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