database

Traits

Traits are a powerful feature in PHP that allow developers to reuse sets of methods in multiple classes without relying on traditional inheritance. In languages with single inheritance (like PHP), a class can only inherit from one parent class. This can sometimes be limiting when you want to share functionality across multiple, unrelated classes. Traits solve this problem by letting you "mix in" methods into different classes.

Seeders

Seeders are way to put data immediately into your tables. All you need to do is populate an array, then use that array to create rows in your table. You can use this data as a test, or to put in actual data without having to type it in multiple times or enter it in a form.

Migrations

Migrations are a method of coding your database schema for both table creation and change control tracking. They allow you build out your tables in code, and track updates to those tables, then use that code to create and update the database tables.

Table Relationships

When working with CakePHP it is important to remember "Convention over Configuration." If you start from the bottom, or back end, the database, and work your way forward correctly, CakePHP will do much of legwork for you, saving you tons of redundant and repetitive work.

If you don't, there are almost always ways to make things work the hard way. An example of this is the relationships between tables. If you name your database tables and fields following CakePHP convention, it becomes trivial to set up relationships between them.

Data Validation

Programming maxim #1: Never trust user input. Data validation in our Model allows us to ensure that the data entered matches what we are expecting and are capable of storing in our database fields.

Database and Model

Now that your application is up and running, it is time to build your data store and interface with that data. We have two options here: We can create the database tables using Migrations or directly in the database, either through the database interface, a web interface, or an IDE interface.