jump to navigation

Rapid Application Prototyping in PHP Using a Micro Framework (Silex) — Part2 Basic Concepts May 27, 2014

Posted by Tournas Dimitrios in Silex.
Tags: ,
add a comment

Silex framework logoWelcome back to the next part of the article series “Rapid Application Prototyping in PHP Using a Micro Framework (Silex)”. Understanding the basic concepts of this  framework (Silex) will make  you feel more comfortable and confident while using it . The goal of this article is to give you a high-level overview of how the Silex framework “works”. Internally, the Silex core is built on top of Pimple, a Dependency Injection Container, and a few components of the Symfony Framework. One of those components is the HttpFoundation component, which defines an object-oriented layer for the HTTP specification. HTTP has a set of predefined methods (also referred as verbs) to indicate what action should be performed on the identified recourse. Actually we don’t have to worry about HTTP-specifications (and all that boring technical detail) as the browser does all the heavy work behind the scenes to build a request according those specifications. The only thing that really interests us is how we should link a request to the corresponding resource (in technical jargon it is named : Routing). In Silex it’s possible to route in two ways . We can either route to a closure or a controller action. As we’ll be going over controllers in later parts of this article, let’s start by looking at how we can route to a closure . 

Typically, browsers support only three verbs (methods) of the HTTP-specification : HEAD , GET and POST. Developers have invented a nice trick to emulate a couple other verbs (read more on the documentation page) .

When users click on a link or enters a URL in their address bar, they’re creating a GET request.When users submit a form, they’re typically creating a POST request. The browser starts to communicate with the server with a HEAD request .