Using a Database in the PHP Application

Using a Database in the PHP Application

This mini project will use the Comedy Clüb example again. You have an application serving the information about shows and comedians, but all this data is currently hard-coded. Begin by moving it into the database.

Migration to another data storage shouldn’t force you to rewrite the whole application. You would still focus on your entities. The only significant change you’ll make is implementing another repository.

Use the Doctrine ORM as an abstraction layer over the database. It will take care of the serialization of entities and make database calls. It will also generate migrations to initialize the database structure based on the entities. A freshly-created database will be empty. To retain the initial data, you’ll create a console command that pushes data from HardcodedRepositoryFactory into the database.

Once the data is stored in a database, it’s possible to change this data without updating the application code. Create an admin panel where users can add new comedians and shows or edit existing ones.

Making an admin panel might sound like a lot of work, but it should be easy. Since you’re using Symfony and Doctrine ORM, you can also use tools built on top of them. You’ll use the EasyAdmin bundle to generate the admin panel.

As a result, you’ll have the same Comedy Clüb website, but this time, users will also be able to edit the show’s program.