filmov
tv
Create Three Symfony Back Ends - Part #19 - Save POST data to the DB in FOSRESTBundle
Показать описание
Our Behat test suite requires that we can POST data into our API in order to setup the Background of any test we run. This is somewhat unusual, and not something I'd advocate in the real world. However, for our purposes I believe it works quite well, and it forces us to get to the implementation (hint: the fun part) as quickly as possible.
Before we can send in data, we need to define what that data is (our Entity), how we can process and validate the incoming data (via a Symfony Form), and how we can save that data off to the database (using Doctrine).
Given this, there are three things we need immediately:
The Album entity
The AlbumType form
The EntityManager
The Album entity is almost identical to that from our basic Symfony 4 JSON API implementation. We won't need to implement \JsonSerializable.
By using the Maker Bundle we can make the entity class stub, and get the associated repository class generated for us for free.
Before we can send in data, we need to define what that data is (our Entity), how we can process and validate the incoming data (via a Symfony Form), and how we can save that data off to the database (using Doctrine).
Given this, there are three things we need immediately:
The Album entity
The AlbumType form
The EntityManager
The Album entity is almost identical to that from our basic Symfony 4 JSON API implementation. We won't need to implement \JsonSerializable.
By using the Maker Bundle we can make the entity class stub, and get the associated repository class generated for us for free.