Symfony at a Glance• Symfony is a PHP framework.• Symfony is a framework, a set of toolsand a development methodology.
A PHP frameworkBasically, a framework consists of:– A toolbox - a set of prefabricated, rapidly integratable software components. Thismeans that you will have to write less code, with less risk of error. This alsomeans greater productivity and the ability to devote more time to doing thosethings which provide greater added value, such as managing guidingprinciples, side effects, etc.– A methodology – an “assembly diagram” for applications. A structuredapproach may seem constraining at first. But in reality it allows developers towork both efficiently and effectively on the most complex aspects of a task, andthe use of Best Practices guarantees the stability, maintainability andupgradeability of the applications you develop
Symfony in 5 minutes Why should I use a framework? When should I use a framework? 6 good reasons to use Symfony The technological benefits of Symfony in 6 easy lessons 10 criteria for choosing the correct framework
Why should I use a framework?A framework is not absolutely necessary: it is “just” one of the toolsthat is available to help you develop better and faster!Better, because a framework provides you with the certainty that you aredeveloping an application that is in full compliance with the business rules,that is structured, and that is both maintainable and upgradable.Faster, because it allows developers to save time by re-using generic modulesin order to focus on other areas. Without, however, ever being tied to theframework itself.
Why should I use a framework?To make long story short.A framework is a pledge of quality, upgradabilityand maintainability of applications at lower cost.
When should I use a framework?• Well... Whenever you need to, while developing a web application or a site, ofcourse!• Why would you have a custom piece of furniture made if you could find onethat perfectly matches your décor, right off the shelf? The same is true forcomputer applications: Before you dive in to create a framework, a little surveywork is in order.• Besides a framework, there are other solutions that are available to developboth Web sites and Web applications: CMSs (Content Management System)and their supplemental modules, as well as packaged professional solutions(CRM, e-commerce solutions, etc.). If their native features line up perfectlywith your immediate and future needs, no question about it: Go for it! There isno point in reinventing the wheel.• On the other hand, when there are specific needs, specific business rules oreven the need to mix building blocks (content and e-commerce, forexample), a framework solution is necessary: it allows an application to bedeveloped that perfectly matches your current needs, while still beinginnovative.
When should I use a framework?To make long story short...but that is not always necessary, especially whenthe requirements are of a more generic nature.
6 good reasons to use SymfonyUsing a Framework is a good thing. Making the rightchoice is even better. Without going too deep into things and inno particular order, here are 6 good reasons to use Symfony, froma strategic point of view1. Reputation2. Permanence3. References4. Innovation5. Resourceshttp://symfony.com/six-good-reasons
6 good reasons to use SymfonyTo make long story short.
10 criteria for choosing the correctframeworkYoure making progress and thats a goodthing! You already know that you are going touse a framework to develop your site or yourapplication. But which one? Here is a checklistthat you can use to avoid making a mistake:
Popularity and community sizeThe more well-known and recognizedthe framework is, the more it will be“living,” evolving and complete: newideas, the number and quality of plug-ins, etc.
PhilosophyThis is the very essence of theframework: it is a fundamental criterion forensuring that it will meet your needs. A tooldeveloped by professionals for their ownneeds will obviously meet the demands ofother professionals.
SustainabilityBefore choosing a framework, makesure that it will be able to keep up with youfor the duration. This simplifies both themaintenance and upgrading of yourapplications.
SupportAnother criterion that should not beoverlooked is the ease of finding answers toyour questions and getting help. Identify thesupport that is available: from the publisher.From a community (mailing lists, IRC, etc.)?From Service Companies(development, support, training)?
TechniqueTo avoid becoming trapped in alabyrinth, it is always preferable to choosean interoperable solution; one thatrespects best practices in terms ofdevelopment (design patterns)
SecurityAny application is potentiallyvulnerable. To minimize risk, it is alwaysbetter to select a framework capable ofensuring security functions (XSSmanagement, for example).
DocumentationIt is an absolute necessity toevaluating the nature, volume and qualityof existing literature about a framework: awell-documented tool is both easier to useand more upgradeable.
LicenseLicenses are important simply becausethey can have a significant impact on yourapplications. For example, an applicationdeveloped using a GPL-licensed frameworkwill necessarily be subject to GPL. On theother hand, this is not the case for an MIT-licensed framework.
Availability of resources on themarketPerhaps you would want to have atechnical team surround you during thedevelopment phase or in the longer term, forboth maintenance and upgrades. In otherwords, make sure that the skills required forthe tool that you are using are available on theopen market.
Try it out!Thats the key! Dont be satisfied withreading reviews, comments and rumors, goodor bad, on the Internet. By testing it out, youwill be able to make up your own mind andensure that you are completely comfortablewith the tool..
HTTP is SimpleHTTP (Hypertext Transfer Protocol to the geeks) is a text language that allows twomachines to communicate with each other. Thats it! For example, when checking forthe latest xkcd comic, the following (approximate) conversation takes place:Symfony2 is built from theground-up around thatreality. Whether you realizeit or not, HTTP issomething you useeveryday. WithSymfony2, youll learn howto master it.
Step1: The Client sends a RequestEvery conversation on the web starts with a request. The request is a text messagecreated by a client (e.g. a browser, an iPhone app, etc) in a special format knownas HTTP. The client sends that request to a server, and then waits for theresponse.
In HTTP-speak, this HTTP request would actually look something like this:GET / HTTP/1.1Host: xkcd.com Accept:text/htmlUser-Agent: Mozilla/5.0(Macintosh)Step1: The Client sends a RequestThis simple message communicates everything necessary about exactlywhich resource the client is requesting. The first line of an HTTP request isthe most important and contains two things: the URI and the HTTP method.The URI (e.g. /, /contact, etc) is the unique address or location thatidentifies the resource the client wants. The HTTP method (e.g. GET) defineswhat you want to do with the resource.
Once a server has received the request, it knows exactly which resource the clientneeds (via the URI) and what the client wants to do with that resource (via the method).For example, in the case of a GET request, the server prepares the resource and returns itin an HTTP response. Consider the response from the xkcd web server:Step 2: The Server returns a Response
Translated into HTTP, the response sent back to the browser will looksomething like this:HTTP/1.1200 OKDate: Sat, 02 Apr 2011 21:05:05 GMT Server : lighttpd/1.4.19Content-Type: text/html<html> <!-- ... HTML for the xkcd comic --> </html>Step 2: The Server returns a ResponseThe HTTP response contains the requested resource (the HTML content in this case), as well asother information about the response. The first line is especially important and contains the HTTPresponse status code (200 in this case). The status code communicates the overall outcome of therequest back to the client. Was the request successful? Was there an error? Different status codesexist that indicate success, an error, or that the client needs to do something (e.g. redirect toanother page). A full list can be found on Wikipedias List of HTTP status codes article.
This request-response conversation is the fundamental process that drives allcommunication on the web. And as important and powerful as this process is, itsinescapably simple.The most important fact is this: regardless of the language you use, the type ofapplication you build (web, mobile, JSON API), or the development philosophy youfollow, the end goal of an application is always to understand each request andcreate and return the appropriate response.Requests, Responsesand Web Development
Requests and Responses in PHPSo how do you interact with the "request" and create a "response" when using PHP?In reality, PHP abstracts you a bit from the whole process:
Symfony provides an alternative to the raw PHP approach via two classes that allow youto interact with the HTTP request and response in an easier way. The Request class is asimple object-oriented representation of the HTTP request message. With it, you have allthe request information at your fingertips:Requests and Responses in Symfony
Symfony also provides a Response class: a simple PHP representation of an HTTPresponse message. This allows your application to use an object-oriented interface toconstruct the response that needs to be returned to the client:Requests and Responses in Symfony
Like HTTP itself, the Request and Response objects are pretty simple.The hard part of building an application is writing what comes in between.In other words, the real work comes in writing the code that interprets therequest information and creates the response.Your application probably does many things, like sending emails,handling form submissions, saving things to a database, rendering HTMLpages and protecting content with security. How can you manage all of thisand still keep your code organized and maintainable?Symfony was created to solve these problems so that you dont have to.The Journey from the Request to the Response
Traditionally, applications were built so that each "page" of a site was its own physicalfile:The Front ControllerThere are several problems with this approach, including theinflexibility of the URLs (what if you wanted to change blog.php tonews.php without breaking all of your links?) and the fact that eachfile must manually include some set of core files so that security,database connections and the "look" of the site can remainconsistent.A much better solution is to use a front controller: a single PHP file that handles everyrequest coming into your application. For example:Now, every request is handled exactlythe same way. Instead of individual URLsexecuting different PHP files, the frontcontroller is always executed, and therouting of different URLs to differentparts of your application is doneinternally. This solves both problemswith the original approach. Almost allmodern web apps do this - includingapps like WordPress.
Stay OrganizedEach "page" of your site is defined in a routing configuration file that maps different URLs to different PHPfunctions. The job of each PHP function, called a controller, is to use information from the request - alongwith many other tools Symfony makes available - to create and return a Response object. In otherwords, the controller is where your code goes: its where you interpret the request and create a response.
Installing a Symfony2 DistributionFirst, check that you have installed and configured a Web server(such as Apache) with PHP 5.3.8 or higher. For more information onSymfony2 requirements, see the requirements reference