</> Code The Pixel

CakePHP 4 CRUD

Asyraf Wahi Anuar - May 10, 2020

Estimated reading time: 1 minute, 0 seconds

CRUD creation using console commands is one of my favourite features in CakePHP. This tutorial will guide you on how to generate CRUD based on the database using console commands. Console applications are ideal for handling a variety of background & maintenance tasks that leverage your existing application configuration, models, plugins and domain logic.

Database configuration
The database should be connected with the CakePHP framework. Refer here to configure the database connection.

Execute the Command Prompt/ Windows Power Shell/ Git Bash and navigate the target directory to your development folder eg: myCake4 folder, using the change directory command:

cd c:/xampp/htdocs/myCake4


Execute this command to generate the CRUD based on the configured database table (eg: users table):

bin\cake bake all users



It will generate:
- Model (...src/Model/Entity/User.php & ...src/Model/Entity/UsersTable.php)
- Controller (.../src/Controller/UsersController.php)
- View (...templates/Users/[add.php, edit.php, view.php & index.php])
- Tests file

Now, navigate to localhost/myCake4/users and it should render the index page for the user table as follows:



The add new user page will render as follows:



Repeat for other tables in your database.

That all. Happy coding :)


Cite this article (APA 6th Edition)

Popular
CakePHP 4 Print PDF Using CakePDF
May, 17 2020
CakePHP 4 Authentication Using Auth...
May, 14 2020
CakePHP 4 jQuery Date Time Picker
October, 01 2018
CakePHP 4 Export To CSV
May, 29 2020
CakePHP 4 Authentication Using...
May, 11 2020
CakePHP 4 File Upload Using Proffer Plugin
May, 15 2020
CakePHP 4 Find, Sort & Count
June, 02 2020
Share
Sharing Link
Click the icon to share