News Archive
PhpRiot Newsletter
Your Email Address:

More information

Create your own framework... on top of the Symfony2 Components (part 4)

Note: This article was originally published at Planet PHP on 9 January 2012.
Planet PHP

Before we start with today's topic, let's refactor our current framework just a little to make templates even more readable:

A // A require_once __DIR__.'/../src/autoload.php'; A use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; A $request = Request::createFromGlobals(); A $map = array('/hello' = 'hello', '/bye' = 'bye',); A $path = $request-getPathInfo(); if (isset($map[$path])) { ob_start(); extract($request-query-all()); include sprintf(__DIR__.'/../src/pages/%s.php', $map[$path]); $response = new Response(ob_get_clean()); } else { $response = new Response('Not Found', 404); } A $response-send(); A

As we now extract the request query parameters, simplify the hello.php template as follows: