Symfony2 Course List

I hope you are having a good week so far! Up here in Lancashire it’s cold, dark and windy. Roll on Summer. There’s a few updates to tell you about here at Code Review recently. These include our new Symfony2 course list.

You can now sort through our videos by Symfony2 course or by single episode. It’s entirely your choice, depending on whether you want to sit down and watch a full course, or dip in and out of courses and watch episodes to suit you.

New videos are being added every week for our subscribing members to watch (membership is currently only $14.99 monthly and we also have an annual option too that gives you a discount).

symfony2 course

Recent Symfony2 course additions include:

  • FOSRESTBundle – everything you need to know about this awesome bundle.
  • Symfony2 services – how to create and use Symfony2 services in your projects.
  • REST Authentication – how to secure your API.
  • GIT Goodness – get more out of GIT.
  • Ansible – Ansible is awesome, how to use it for lots of your common tasks.
  • Faker Bundle – let this do your dirty work.

We always welcome Symfony2 course requests, questions and recommendations from our subscribers and we are here to teach and help you become a better Symfony2 developer – whether you are learning for yourself or for a business.

We’re also working on improving the layout and look of the site all of the time, so if you have a suggestion or idea please do let us know. We want this site to be a brilliant place to visit and learn from for everyone.

Free Symfony2 Videos

One last thing! Have you subscribed to our YouTube channel yet? If not make sure you are a subscriber on there so you don’t miss out on any newly published videos. Plus they give you a good idea of how we teach and demonstrate Symfony2. If you like our YouTube channel, you will love being a member of Code Review Videos.

Have a great rest of the week – and look forward to seeing you on the inside!

 

Symfony Book Introduction

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.

Controller

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
  • Image
  • 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

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.

Symfony book

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.

Testing

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.

Validation

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.

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.

Security

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.

HTTP Cache

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.

Translations

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.

Service Container

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.

Performance

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.

Internals

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.

Diving Deeper!

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.

Symfony Getting Started

Symfony Getting Started

In this post we will point you in the direction of some great Symfony getting started videos. On first impressions Symfony can appear really difficult and is easy to get freaked out by. Chris helps take you through different segments of learning Symfony 2, step by step in this series.

You can also visit our dedicated members area for lots more beginners training videos.

Symfony getting started videos

Here are some of our most popular Symfony getting started topics:

In this beginners video, you learn out to set up your development environment in Symfony 2 so that you can begin working on your first project.

Making sense of it all!

In part one, you set up your Linux server that allowed us to install your Symfony getting started essentials. In this second video you will look at the files and folders that were downloaded with the default install and learn what they all mean. It’s a very high level overview, and designed to give you more of an understanding of the ways that the files and folders fit together.

Symfony Bundles

Previously we looked at the default install that you get with Symfony 2. Next you will learn how to set up your first Symfony 2 bundle. The video features routing, a controller and Twig templates.

Bootstrap

We looked at a basic controller in the last video with a very basic template. When you put Symfony into practice in real life, you are more likely to use a web framework to help speed up your development. This is where we will use Twitter Bootstrap, which has recently been rebranded to just Bootstrap. Bear in mind that there are other ways to set up Bootstrap and this is the way Chris has had success with.

Backend Database

The previous video showed you some front end Symfony getting started tips with Bootstrap. In the next training video we will look more at the backend, and connecting Symfony 2 to our database. Chris talks you through Doctrine Object Relational Mappers (ORM). It can feel overwhelming as a beginner to learn a new way to interacting with your database, new concepts, configuration, set up and more. Hopefully this video will help demystify what appears at first to be a very complicated way of doing something, and let you see that it is well worth learning.

Symfony 2 Forms

We have looked at Doctrine, which allowed you to create, update and delete entities in your database. In this next video, we look at a corner stone of modern web development – the Symfony 2 form. Symfony 2 has a great form builder. Let’s look at basic forms, how to render them in your templates, how to handle, validate and save submitted form data and how to repopulate a Symfony 2 form with existing data.

Join Us!

In this Symfony getting started post, we’ve looked at a few of Chris’s introductory videos. You can check out tons more beginners and intermediate Symfony 2 tutorials in our members area.

We hope to make learning Symfony something fun and more straight forward than struggling along on your own. Have you got something specific you’d like to learn, a particular struggle or just a question about Symfony? Just get in touch and ask via our contact page. Hope to see you inside!

FOSRESTBundle for REST API

FOSRESTBundle is a tool to help you in the job of creating a REST API with Symfony2. Let’s take a closer look at what it all really means and where to download it and get started.

What is FOS?

FOS stands for Friends of Symfony. It’s a group of people who begun collaborating on the KNP Labs User Bundle. They decided to create a dedicated space for Bundles that they maintained as a group. Over time this has led to many more popular bundles being created via the group.

Check out the Friends of Symfony GitHub to see the bundles available.

What is REST?

REST stands for Representational State Transfer. It is resource-based rather than action-based. In a RESTful API, we’re talking about things instead of actions.

REST typically runs over HTTP (Hypertext Transfer Protocol) and has several architectural constraints:

It decouples consumers from producers.

It leverages a layered system.

It leverages a uniform interface.

Able to leverage a cache.

Stateless existence.

Features of the FOSRESTBundle

The FOSRESTBundle gives us great tools to allow the quick development of RESTful API’s and applications using Symfony2. Once you have confidence in using it, you’ll quickly find so many other possibilities become available including apps, Angular JS front-ends and as well as other opportunities.

Some key features include:

  • Generate URLs following REST conventions using a custom route loader.
  • Accept header format negotiation.
  • It has an exception controller used for sending HTTP status codes.
  • RESTful decoding of HTTP request body and accept headers.
  •  View layer for allowing output and format agnostic controllers.

Benefits of FOSRESTBundle

REST is likely to keep growing as more and more businesses seek open, well-defined interfaced for developing applications and infrastructure services. It’s very useful and worthwhile to learn.

Advantages of learning REST include:

  • It is designed for using over Open Internet/Web. It’s a better choice for web scale applications and cloud-based platforms compared to SOAP (Simple Object Access Protocol) and is often the choice for the architecture of internet services these days.
  • RESTful web services are easily leveraged by most tools.
  • REST forbids conversational state, meaning we can scale very wide with the addition of server nodes behind a load balancer.

Getting Started with FOSRESTBundle:

You can find the FOSRESTBundle here. Installation is a quick one step process. There are six main sections on the download page to look over before you begin. Check out the config references too, and there are also some example applications too that can be used as a guideline.

FOSRESTBundle

Ready to learn to code a RESTful API?

In our RESTful API course using FOSRESTBundle, you can watch and learn how to set up, configure and implement a REST API. Sometimes it’s easier watching than trying to figure stuff out for yourself, plus you can also ask questions!

The course covers all of the basics such as GET, POST, PUT and DELETE. This is along with handling related data collections, leveraging the Symfony2 Forms component, and very importantly, this is all done using test driven development techniques. Let’s get cracking and we hope to see you on the inside!

 

Symfony 2 Form: A Short Guide

A web form or a HTML form is basically a page that allows a user to enter information that is then sent to a server for processing.

This is a short guide to the Symfony 2 form. Symfony has a very powerful form component that makes using forms simpler when compared to HTML forms, although forms can still be very challenging to get your head around and learn.

Within Symfony there is a standalone form component library that can also be used with other non-Symfony projects.

Symfony 2 gives us a wide range of ways that we can customise how a form is rendered. Form fragments can be used to render just one part of a Symfony 2 form, or to render each part of the form.

Symfony 2 form elements can include:

  • Simple text input
  • Text area
  • Select drop down list
  • Checkboxes
  • Radio buttons
  • File selection
  • Reset button
  • Submit button

Creating a form

We can write recipes with form objects using the form builder. You can also import a form theme to customise your form, or use the default Symfony 2 form theme that comes as standard with Symfony.

When using forms in a template in Symfony, you can use functions (for rendering each bit of the form) and variables (less often used, to obtain any information about any field).

To get started with forms, watch our video on YouTube, an introduction to forms in Symfony 2.

This video covers a range of topics including:

Creating a basic Symfony 2 form

It covers building the form inside our controller and rendering the form in our view.

How to handle the submission of the form back to our controller (where user presses submit).

image-symfony-2-form.png

Rendering your form

There is noob mode that involves pasting it in, and real world mode that is more indepth and where your form gets customised.

Changing the action and method of a form

This covers posting to GET and where your data is being posted to.

Form classes

Creating reusable forms is discussed, and how to separate our form logic from our controller.

Form validation

You shouldn’t trust the raw data input from a user. Symfony provides two methods of form validation, there is the front end and server side. Front end shouldn’t be relied upon and you should ideally always implement server side validation. How to do this is explained.

How to prevent cross site request forgeries (CSRF)

This involves a single line of code and is not as complicated as it may sound.

More resources to learn about the Symfony 2 form:

http://symfony.com/doc/current/book/forms.html

https://github.com/symfony/Form

The best way to learn is by doing so start practicing!