Scaffolding using cake PHP

Scaffolding using cake PHP


Scaffolding is a technique supported by MVC frameworks which helps the programmer to write specification that describes the usage of application database. The compiler uses this specification to generate code. The application in turn uses this code to create, read, update and delete database entries, effectively treating the template as a “scaffold” on which to build a more powerful application.

Scaffolding is an evolution of database code generators .It was popularized by the Ruby on Rails framework.Scaffolding is a set of automatic actions for starting development work faster.

CakePHP’s scaffolding is pretty cool. It allows you to get a basic CRUD application up, and going in minutes. Developer hates creating multiple forms. Scaffolding analyzes your database tables and creates standard lists with add, delete and edit buttons, standard forms for editing and standard views for inspecting a single item in the database.

Use Case

The use case is to demonstrate a simple functionality that is adding the products under a category.

What we need to do:

  • Install LAMP stack.
  • Create the basic set up for cakephp framework.

To achieve scaffolding, follow the steps given below:

Create category and product controller:

  • app->Controller – >CategoriesController.php
  • app->Controller – >ProductsController.php
    • Add the code given below in CategoriesController.php,
    • Add the code given below in ProductsController.php

Create category and product Models to get data’s from data base:

  • app->Model – >Category.php
  • app->Model – >Product.php
    • Add the code given below in Category.php:
    • Add the code given below in Product.php:

Set Up data base as below:

  • Create the tables given below for category and product:
    After setting up the above configurations, run the categories controller to view the list as /categories
  • Category List:

prince 1

  • Product list:

prince 2

  • To add New product:

Under actions click on add new category,

prince 3

  • To  edit / Delete product/ categories:

prince 4

  • Challenges:
    • We need to customize the cake php data model for large and complex data bases.
    • To create relationship between the databases, we can use the cake phpAssociations like $hasOne, $hasMany, $hasAndBelongsToMany, $belongsTo etc.


  • Scaffolding is an Automatic CRUD creation. It has both advantage and also disadvantages. It can be used for the application which is not dynamic. It doesn’t take much coding or time to create the basic application with database interaction.
  • This is an in-built way to quickly add a front end onto any database (or set of models) to  visualize better.



9129 Views 2 Views Today