Back to Browse

How to use data transfer objects (DTO) in Symfony API application

29.8K views
Sep 10, 2020
17:57

In this #PHP programming tutorial I explain how and why you should use data transfer objects (#DTO) for response in your #Symfony applications. I demonstrate in real-life example how you can prepare your code to use DTOs. I also share some useful tips: * how to separate data in DTO for customers and admins using serialization groups * how to "turn off" processing of specific fields if they are not in use for current serialization group * how to add virtual property into DTO In this video I use Symfony 5 with PHP 7.4 but this tutorial is still relevant for older versions of Symfony framework or PHP. ⭐️ Final result you can find here ⭐️ 🔗 https://github.com/Cap-Coding/symfony_api/tree/data_transfer_objects ⭐️ Support channel on Patreon ⭐️ 🔗 https://www.patreon.com/capcoding ⭐️ Resources ⭐️ 🔗 To send request I use a great free tool Postman https://www.postman.com/ 🔗 Serialization annotations https://jmsyst.com/libs/serializer/master/reference/annotations 🔗 DateTime format documentation https://www.php.net/manual/en/datetime.format.php 🔗 Book O'Reilly "Head first design patterns" Amazon: https://amzn.to/2KVHD0D (new edition) Amazon: https://amzn.to/2NMfTN9 Amazon DE: https://amzn.to/2Xq3TCt 🎥 All tutorials for Symfony CRUD API https://www.youtube.com/playlist?list=PLKQc-wMFDsrEt6U5LKLETR2d4nhW0ieNI Get € 20 on Hetzner Cloud hosting: 💲https://hetzner.cloud/?ref=GyXEuMSuxUBq Register domain without hassle on GoDaddy 💲https://letyshops.com/r/godaddy-87becf0c4e38 ⭐️ TABLE OF CONTENT ⭐️ 00:00:00 Introduction 00:02:00 Application structure 00:03:04 Define classes for DTOs 00:05:19 Create transformers 00:08:57 Using transformers in controllers 00:09:39 DTO without corresponding entity 00:11:46 Serialization groups 00:13:51 Improve performance 00:15:49 Virtual property 00:16:35 Transformer validation

Download

0 formats

No download links available.

How to use data transfer objects (DTO) in Symfony API application | NatokHD