PHP, Symfony, Twig, MySQL
Book review application created in PHP language using the Symfony framework, rendered in Twig templates and with a database in MySQL.
Check the project on Github
Reviook is a book reviews application, in which different users can access a database with books and write comments and reviews about those they have read, and these comments can be seen by other users of the application to know opinions from others. The application is personally designed from scratch and programmed using PHP through the symfony framework, and with a relational database created with MySQL. To use PHP, symfony and MySQL properly, we start from a Docker container that already has all these tools incorporated.
The Symfony framework of PHP allows us through the composer to add packages of functionalities to our application. Two of the essential packages for this project will be annotations and twig. Annotations allows us to create different routes in the application controller file, both static and dynamic linked to parameters. The different routes have associated functions that extend from the Abstract class to execute renders, in this case HTML templates to which the information we need is passed. To create these HTML templates and be able to render from the back we use Symfony's Twig package, which allows us to create HTML blocks with variable content, in addition to other functionalities.
The application requires the creation of different data models, in this case they the book model, the user model and the review model, which contains information on the other two models. These models are created as symfony entities through the maker package, where the properties and value type of each model are set, thereby creating a MySQL table. This entity is incorporated through migrations to our relational database. The complexity of these tables lies in the interrelation between the tables, this relationship is established through relation type properties within symfony, and sets the foreign keys when the entities are transferred to MySQL tables.
One of the main functionalities of the application is the existence of authentication. This is done through the security package. This package allows us to create a login strategy accompanied by a logout strategy whose logic is created in a new controller that accesses functions from an external php file in the security folder. This package also allows us to create authorization logics, establishing parts of the application with restricted access that require a user to have logged in. Through the creation of a user role and the security.yaml file we restrict access to all those routes that start with /myAccount. The registration strategy will be created through simple forms.
The maker package allows us to create forms through make:form, through which we can make post requests to add information to our database, information that our application will then render. First of all we have a user registration form to add users to the users table of the MySQL database. Apart from this form we have the form for the main objective of the application, add reviews. The review form is linked to the previously created review entity. In it the user writes his review, which will become the value of the text property of that review. The other properties of the review, the user who writes it and the book to which it is associated, are set directly without the need for the user to indicate it.
The assets package allows us to easily access the public folder of our application, a folder that will be accessible on the client side and that will include the images used, the different style sheets for the Twig templates and certain additional JavaScript functions that we create, such as in this case the one that allows us to expand and contract the menu of the navigation bar.
© Pablo Pacheco