Intro with Twig CRUD - List

For a website to feel modern, the days of click button > entire page refresh > repeat being an acceptable user experience are over. Instead, our users want swanky UI with dynamic updates, load-on-scroll, 'real time' form field validation, and all that jazz.

PHP doesn't seem cut out to offer this. Certainly, with Symfony, this isn't the experience you get right out of the box.

But what if you could get the best of both worlds?

What if you could leverage everything you know about PHP, and still get to use Angular, React, Ionic, or any other modern front end framework?

You'd probably think that this would be, at the very least, quite difficult. In this video series I will show you that this simply isn't the case.

In this video we will cover how quickly we can lay a foundation to use Symfony 3 and Twig to create what you likely think of as a typical PHP web application / website. It's going to be click > refresh page > click > etc.

This is an important first step as it covers how we might currently be doing things.

By the end of this video we will have:

  • added a BlogPost entity to our new Symfony 3 project
  • used Will Durand's Faker Bundle to seed our database
  • created a listAction in our controller to show all our entities (Read)
  • created a table styled with Bootstrap 3 to easily view our Blog Posts

In the next three videos we will see how to add (Create), edit (Update), and remove (Delete) these entities - the 'old fashioned' way - to cover the basics of CRUD.

After this we will need to rethink our approach.

The foundations are largely the same. But we will no longer use Twig to return static HTML.

Instead, we will switch to outputting JSON. This might make things - initially - more confusing. But this step is important.

Once we start creating our RESTful API, we need to switch from CRUD to GET, POST, PUT, and DELETE.

These verbs enable the same functionality as our Twig approach. But this time, we need to provide our own front-end. We will do this firstly with React, and then secondly with Angular 1.5.

We aren't going to be cranking out some scary enterprise behemoth. Instead, we will keep things as simple as possible, aiming to cover the basics.

I have nothing against Laravel, Lumen, or any other suggestions that are frequently recommended when developers ask what framework to use for their REST API. Anything that keeps PHP moving forwards is a good thing, in my opinion.

But I do want to make the case for Symfony as the basis of your API. Why? Because it's an amazing platform to build upon. And it's much easier than it may initially seem.

Hopefully by the end of this series you will agree with me :)

Code For This Video

Get the code for this video.