The Symfony book is basically the bible for Symfony 2 developers. Best of all it’s completely free for you to download and start learning right away. You can either read it on the website or get the PDF.
Here’s our short guide to the key content covered and a summary of what you will learn.
Symfony and HTTP Fundamentals
The Symfony book has a great introduction chapter for everyone to read. It explains the fundamentals of web development – HTTP. After covering the basics of HTTP, it ends with a summary of the Symfony framework itself:
- It is a PHP library
- It encompasses a set of components, as well as third-party libraries
- It gives developers solid configuration and a library that ties everything together
- The goal is a consistent experience
- The framework itself is a bundle/plug in and can be configured or entirely replaced
- Your app development isn’t imposed on by Symfony, due to it’s powerful tools
- Beginner/normal users can quickly begin implementing Symfony, whilst for advanced users, the opportunities are endless
Symfony versus Flat PHP
This chapter is a great introduction for those who are not sure why to go with Symfony 2. It explains clearly the reasons why Symfony 2 gives you the ability to develop more efficiently, with solid code, rather than with flat PHP.
The Symfony book guides you through the process of creating a basic app in flat PHP, then shows you how to make it more organised. It takes you a journey and by the end of the chapter you understand how Symfony can be so beneficial in helping you with boring, mundane tasks and create good solid code.
Installing and Configuring Symfony
The third chapter helps you set up and begin running with an application built on Symfony, using downloadable starter projects, so that you can begin developing right away. Very helpful! It covers composer, getting installed, set up and starting, plus source control.
Creating pages in Symfony
In this chapter, as the title suggests, it’s all about starting to make pages. A new page is a fairly simple 2-step process that involves creating a route defining the URL, specifying a controller as a PHP function, creating a controller that receives the request and turns it into a Symfony Response object that is then sent back to you.
It basically mimics the way the internet works; interactions on the web are initiated with a HTTP request, and the job of the application is to interpret and return a HTTP response. Things get more interesting in upcoming chapters.
The Symfony book next goes into even more powerful tricks and tools. In fact, the more you learn, the more you really appreciate what this framework can do.
In this chapter we learn about controllers. You create these PHP functions which then takes the information from the HTTP request, constructs it and then returns a HTTP response. This response could include:
- HTML page
- XML doc
- JSON array
- 404 error
In fact the controller encompasses whatever logic you decide on, for your app to show the rendered content. The chapter demonstrates how a controller would render a page.
Routing is a system in Symfony 2 that allows the mapping of a URL of incoming requests, to the controller that processes the request. Having pretty-looking URLs is kind of important. Making a URL change using Symfony’s router involves a simple change.
The Symfony router lets you create complex routes that map to the controller, generate URLS within templates and controllers, load up resources using bundles and allows debugging.
Creating and Using Templates
In this chapter of the Symfony book, we learn how to write flexible templates for returning content, populating email bodies, short cuts and ways to extend templates and reuse your template code.
Templating is so important because of the controller being responsible for handling each Symfony app request. The controller sends off the work to other places so the code can be tested and also reused.
Where HTML, CSS or other content is needed to be generated by the controller, it hands the work to the templating engine. There are two different template renderers, traditional PHP templates and Twig templates.
Databases and Doctrine
Symfony comes integrated with Doctrine1. This is a library that gives you powerful tools that allows you to focus on your objects and to use any PHP object to hold your data.
It relies on mapping metadata info, and allows the creation of complex queries. In the eight chapter of the Symfony book, we learn about the philosophy of Doctrine fixtures and see that working with a database is fairly simple.
Databases and Propel
The propel integration is described in this chapter. A challenging task in development is persisting and reading info to and from a database. Symfony doesn’t come with an object relational mapper (ORM) but instead you can install propel for this.
We love testing at Code Review and in past projects, testing is one of the most important actions you can take throughout the entire development process.
Whenever you write a new line of code, you can add new bugs. To ensure good solid code from start to finish, you can test your code with functional and unit tests. It gives you peace of mind in the real world when doing client work.
You don’t need permission to test, just do it as part of your own quality control of your work.
It’s common to do validation when creating web applications. Data that you enter in forms needs to be validated, and before it gets added to a database or passed on to a web service. It enables you to guarantee that any object is valid.
Symfony comes with a powerful validator component, which makes this easy and clear to do. It can be used anywhere with an object, but is most often used with forms.
This chapter of the Symfony book covers the important building blocks of forms and guides you through building a complex form from the start. The first goal is translating data from an object to a HTML form so the user can modify the data, the second goal is to the take the submitted data and reapply it to the object.
We learn the main features of the form library. For many developers, using HTML forms can be very challenging, thankfully Symfony keeps things relatively simple in comparison with the integration of the form component.
This is a really indepth chapter and covers the serious issue of getting the security right for your application. The security component in Symfony 2 follows a solid model that is based on authentication and authorisation.
There is a 2-step process involved, the first being the security system identifies the user and has to authenticate them, the second step is determining access to a given resource.
The framework of Symfony is designed to follow HTTP and caching is included within this. Being able to use the cache system means you can overcome some of the headaches that can ensue as your site grows.
The processing that is usually performed for each request should only be done once, and that’s what we learn in this chapter of the Symfony book, and what caching helps you accomplish.
We learn the translations component in this chapter of the Symfony book. The process has three main steps. These include enabling and configuring Symfony’s translation service, abstract messages/strings, translating each message and managing the users locale.
The service container allows the standarding and centralising of objects in an application. It essentially makes your life a bit easier. All of the core Symfony classes use the container.
In this chapter of the Symfony book we learn how to extend, configure and use any object using the service container. This includes customising objects from any third-party bundle. It helps you to write code much more easily, so that it is reusable, testable and decoupled, making it simpler to maintain.
This chapter of the Symfony book is all about making things even quicker. We learn some of the most common, powerful ways to do this. It includes using a byte code cache, composers class map functionality, caching the autoloader and using bootstrap files.
You only need to read this chapter of the Symfony book if you really want to know how Symfony works underneath. It uncovers some of the code layers. If you’ve already read and understood the Symfony book this far, you might as well keep going and learn Symfony more indepth, or if not, set it aside for now until you are read to learn more about behind the scenes.
The Symfony Stable API
This very brief final chapter, the Symfony book talks about stable API. It covers what this is, and a list of components that are publicly tagged API.
Ready to start putting what you’ve learned in the Symfony book into practice?
Overall the Symfony book is an essential part of learning Symfony. Many people learn in different ways, and it’s always good to watch and learn how things are done in real life rather than just reading text.
Here at Code Review you can watch a range of free and members only practical training videos. Each Symfony 2 tutorial is broken down into short segments to make your learning easier.