- CakePHP - version 4
- PHP - version 7 & above
Lets go through the project structure in this application by getting to know the location of route, controller and how it works.
-
Route
In this file where we define route or url for client to call. More details, please view on the code level in routes.php in line 81 - line 94.
- Location - config/routes.php
-
Controller
In this file, where we define our logic and return the data. Since we are using
Laravel Action Classes Concept, all the logic define in action. More details can view inCardsController.php.CardsController.phpis extends class fromsrc/Controller/ApiController.php. To make more clean code, we createsuccess()method inApiController.phpjust to return a data in fix structure.- Location - src/Controller
-
Action Class
In Laravel, there is a call Action Classes, where one action has one class. Why use Action Class? just because to make it as Single Responsibility Principle. This kind of method make it more simpler, cleaner and easily scalable. More details can view in
GetCardList.php.This action class has their own interface also known as contract. In order to able to use Contract in Controller, we need to register and bind the Contract with the Action Class by defining in
src/Application.php. More details you can view insrc/Traits/BindService.php- Location - src/Actions/Card
-
Migration
In CakePHP, we can simply create a table we use migration file. There is a command to generate a migration file, eg:
bin/cake bake migration CreateCards. By using migration file, it easy for other team members to have a same table structure that we have and see the history of table structure.- Location - config/Migrations
-
Seeder
As a developer, we do need have a data for a clearer vision what kind data that we present to the client. Thanks to seeder, instead of create manually in table, we can create a seeder class, just to automate insert multiple dummy data.
- Location - config/Seeds
To run this project, you need to run several command.
composer install- To install all the packages that require for this project.bin/cake migrate- To migrate the table into database.php vendor/bin/phinx seed:run -s CardsSeed- To seed a data into table.bin/cake server- To run the project.