In this video we will finish up our basic CRUD application with Symfony 3 and Twig by implementing the 'D' - deleteAction.

The logic for this action is incredibly simple - we don't even need a view.

In short we will grab the BlogPost from the passed in id, and remove it. Simple.

Once the BlogPost has been removed, we will redirect the user (via a browser redirect / page reload) to the list view.

We'll add in a touch of error checking by saying if the passed in id doesn't exist then redirect the user to the list view all the same. Not the best, and we could certainly add in a nice Flash Message to give the user a little heads-up as to what the heck just happened. But for the moment we aren't worrying about the visuals, just the 'raw' flow.

Out of all the actions, the deleteAction is the closest to the way the API implementation will work. The difference will be around what happens with redirects versus simply returning status codes.

Wrapping Up The Twig Implementation

At this stage we have seen how to Create, Read, Update, and now, Delete.

I've intentionally kept these videos on the short side as these processes are doing, largely, what frameworks like Symfony aim to make easiest out-of-the-box.

The really nice part is that re-writing these methods in their RESTful API equivalents is - dare I say - equally as quick. Once you have been shown ;)

The hard part, in my opinion, is figuring all this out for yourself, the first time you need to do it. After you have a working baseline, you can always refer back to that and do the old copy/paste.

There is a little more that we will come back and add in - pagination, filtering, and sorting. Again, for the moment, we are keeping things as basic as possible.

In the very next video we will switch to creating our CRUD setup using Symfony 3 and FOSRESTBundle to create our API.

Code For This Episode

Get the code for this episode.

Share This Episode

If you have found this video helpful, please consider sharing. I really appreciate it.


Episodes in this series

# Title Duration
1 Intro with Twig CRUD - List 06:03
2 Twig CRUD - Create 03:25
3 Twig CRUD - Update (Edit) 02:43
4 Twig CRUD - Delete 02:36
5 Simple Symfony 3 RESTful API Setup 05:32
6 API - GET a Single BlogPost 04:51
7 API - GET a Collection of BlogPosts 02:20
8 API - POST to Create New Data 06:30
9 API - PUT and PATCH to Update 04:11
10 API - DELETE 03:34
11 Angular - Setup, Styling, and GET All 09:19
12 Angular - Refactoring 10:23
13 Angular - Create (POST) 06:54
14 Angular - Update (PUT) 08:41
15 Angular - Remove (DELETE) 06:44
16 React - Intro, Setup, and GET all 06:54
17 React - Refactoring 09:14
18 React Router 04:41
19 React - Create (POST) 13:13
20 React - Update (PUT / PATCH) 12:40
21 React - Delete 11:00
22 React - Tidy Up, and Finish 04:14