CakePHP Working with Database - CakePHP

How to work with Database using CakePHP?

Running with database in CakePHP could be very clean. we will apprehend the CRUD (Create, read, update, Delete) operations on this chapter. before we continue, we need to create the following users’ table within the database.

similarly, we additionally need to configure our database in config/app.php report.

Insert a Report

To insert a document in database, we first need to get hold of a table the usage of TableRegistry elegance. we are able to fetch the instance out of registry the usage of get() approach. The get() method will take the name of the database table as a controversy.

This new example is used to create new entity. Set essential values with the example of recent entity. we've to name the save() technique with TableRegistry elegance’s instance with the intention to insert new document in database.

Example

Make changes in the config/routes.php report as shown inside the following software.

config/routes.php

Create a UsersController.php record at src/Controller/UsersController.php. replica the following code in the controller record.

src/controller/UsersController.php

Create a listing customers at src/Template and below that directory create a View report called upload.ctp. replica the following code in that report.

src/Template/Users/add.ctp

Execute the above example through travelling the subsequent URL.

http://localhost:85/CakePHP/customers/add

Output

Upon execution, you may obtain the following output.

working with DB

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

CakePHP Topics