Home > Framework > CakePHP > About CakePHP

What Is CakePHP?

About CakePHP

The Official website: http://www.cakephp.org/

CakePHP is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications. Using commonly known design patterns like MVC and ORM within the convention over configuration paradigm, CakePHP reduces development costs and helps developers write less code.

List of features you’ll enjoy when using CakePHP:

  • Active, friendly community
  • Flexible licensing
  • Compatible with versions 4 and 5 of PHP
  • Integrated CRUD for database interaction
  • Application scaffolding
  • Code generation
  • MVC architecture
  • Request dispatcher with clean, custom URLs and routes
  • Built-in validation
  • Fast and flexible templating (PHP syntax, with helpers)
  • View Helpers for AJAX, JavaScript, HTML Forms and more
  • Email, Cookie, Security, Session, and Request Handling Components
  • Flexible ACL
  • Data Sanitization
  • Flexible Caching
  • Localization
  • Works from any web site directory, with little to no Apache configuration involved

What Is MVC?

MVC stands for Model, View, and Controller. It aims to separate your app in these 3 components:

* The Model: this is your data (and some code to easily manipulate it).
* The View : this is the way you represent you data.
* The Controller : this is the data processing, the glue between the Model and the View.

It’s a very nice way to build application because it’s clear and easy to maintain. It allows you to reuse a lot of code or to change your input source (if your data base change, only your model change, the rest of your application works the same !)

Designers can work on the views without needing to know how your app is built.

AJAX apps fit better because their are few dependencies between you app components.

Input –> Processing –> Output
Controller –> Model –> View

The Model represents enterprise data and the business rules that govern updates and access to this data. The Model also encapsulates application state, responds to state queries and notifies views of changes.

The View renders the contents of a model and also requests updates of the models. Another feature is that it can access enterprise data through the model and specifies how that data should be presented.

The Controller processes and responds to events, typically user actions and may invoke changes on the model.


The following are the list of benefits and drawbacks in MVC architecture.

Benefits of MVC

– Substitutable user interface :
Different views and controllers can be substituted to provide alternate user interfaces for the same model.

– User interface components:
Because MVC demands that the user interface of an application be structured into a hierarchy of objects and defines a standard relationship between these objects, generic versions of these objects are possible. They are usually called user interface components and no modern GUI environment is without a full complement of them usually combining view and controller into a single object.

– Multiple simultaneous views of the same model:
Multiple different views can be active at the same time. Each view simultaneously and independently presents the same information from the model.

– Synchronized views:
The change propagation mechanism insures that all views simultaneously reflect the current state of the model.

– Easier user interface changes:
Changes affecting just the user interface of the application logic become easier to make.

– Easier testing :
With MVC it can be easier to test the core of the application, as encapsulated by the model.

Drawbacks of MVC

– Increased complexity :
If reading this page doesn’t convince of you the complexity of this pattern, consider all of the auxiliary patterns that co-occur with MVC.

– Close coupling of views and controllers to model :
Changes to the model interface require parallel changes in the view and may require additional changes to the controller. certain code changes become more difficult.

– Potential for excessive updates :
The change propagation mechanism can be inefficient when frequent model changes require many change notifications. This is generally not as much of a problem if a passive model is used.

– Close coupling between view and controller:
strict separation is difficult if not impossible.

Till this we are aware of

What is CakePHP?

What is MVC?

The benefits and drawbacks of using MVC architecture?

The key features of using CakePHP.

Now we are going to

From where to download the CakePHP files?

How to install in our system?

How to run CakePHP application?

What are modifications require in apache server to run the CakePHP in localhost?

List out the errors while we integrating the CakePHP.

* From where to download the CakePHP files?

From the URL: http://www.cakephp.org ,download the latest version of CakePHP and unzip in your system, at the appserv->www folder and the folders and file are

App, cake, vendors, one .htaccess file and index.php file.

* How to install in our system?

Now CakePHP files are in your local host folder, at the appserv – www folder .

Create a database for your application.

* How to run CakePHP application?

Run the CakePHP application in your localhost like :

Run URL at the web browser like : http://localhost/CakePHP/

The following screen will be appearing :


– Open the file core.php which is at app/config/ folder and modify the line

Search for this line :


Modify the line to :

Configure::write(‘Security.salt’, ”);

Then salt error is removed when CakePHP is running.

To enable database configuration like :

Rename config/database.php.default to config/database.php

And do the changes like :

Var $default = array (

‘Driver’ -> ‘mysql’,

‘persistent’ => false,

‘host’ => ‘localhost’, // data base host name

‘login’ => ‘root’, // username for the data base

‘password’ => ‘root’, // password of data base

‘database’ => ‘CakePHP’, // Data base name

‘prefix’ => ”,


* What are modifications require in apache server to run the CakePHP in localhost?

Uncomment the line in httpd.conf to run the CakePHP

LoadModule rewrite_module modules/mod_rewrite.so

<span style="font-size:10pt;"> </span>

Add some line of code in this file :

<Directory “C:/AppServ/www”> In from this line search for

<span style="font-size:10pt;color:black;"> </span>

<span style="font-family:&quot;color:black;">AllowOverride None </span>

<span style="font-size:10pt;color:black;"> </span>

<span style="font-family:&quot;color:black;">modify this line to </span>

<span style="font-family:&quot;color:black;"> </span>

<span style="font-family:&quot;color:black;">AllowOverride All</span>

<span style="font-size:10pt;color:black;"> </span>

<span style="font-family:&quot;color:black;">Then restart the apache and run the CakePHP in your local system , it is perfectly run the CakePHP application.</span>

<span style="font-family:&quot;color:black;"> </span>

* List out the errors while we integrating the CakePHP

<span style="font-family:&quot;color:black;"> </span>

<strong><span style="font-family:&quot;color:black;">- The application is run perfectly but css is not applied for this application</span></strong>
<span style="font-family:&quot;color:black;"> .</span>

<span style="font-family:&quot;color:black;"> </span>

<span style="font-family:&quot;color:black;">For this we have check for the mod_rewrite option is enable or not in the phpinfo.php<span> </span>, to search for this </span>

<span style="font-family:&quot;color:black;"><span> </span><a href="http://localhost/phpinfo.php">http://localhost/phpinfo.php</a> </span>

<span style="font-family:&quot;color:black;">In this see the line like mod_rewrite at the load modules section.</span>

<span style="font-family:&quot;color:black;"> </span>

<span style="font-family:&quot;color:black;"> </span>

<span style="font-family:&quot;color:black;"> </span>

<span style="font-family:&quot;color:black;"> </span>

<span style="font-family:&quot;color:black;">Till this we are aware of how to install CakePHP in our system, and how to run application are completed, now going to know and create a sample application using our CakePHP.</span>

<span style="text-decoration:underline;"><span style="font-family:&quot;color:black;"><span style="text-decoration:none;"> </span></span></span>

The Sample Application Using CakePHP.

– What is scaffolding ?

Application scaffolding is a technique that allows a developer to define and create a basic application that can create, retrieve, update and delete objects. Scaffolding in CakePHP also allows developers to define how objects are related to each other, and to create and break those links.

CakePHP scaffolding is pretty cool. It allows you to get a basic CRUD application up and going in minutes. So cool that you’ll want to use it in production apps. Now, we think its cool too, but please realize that scaffolding is… well… just scaffolding. It’s a loose structure you throw up real quick during the beginning of a project in order to get started. It isn’t meant to be completely flexible, it’s meant as a temporary way to get up and going. If you find yourself really wanting to customize your logic and your views, its time to pull your scaffolding down in order to write some code. CakePHP’s Bake console, covered in the next section, is a great next step: it generates all the code that would produce the same result as the most current scaffold.

To add scaffolding to your application, in the controller, add the $scaffold variable:


class CategoriesController extends AppController {

var $scaffold;



But when we are using scaffold like this we loose the structure of controller, it is difficult to modification or customization of controller.

At in the model :


class User extends AppModel {
    var $name = 'User';
    var $displayField = 'first_name';


Run scaffolding of CakePHP in the console:

For The new version of CakePHP :

Command :

Set path like at the path section : c:\appserv\www\cakephp\console\

And run the commands follow this order

C:\AppServ\www\cakephp\app>cake bake model

C:\AppServ\www\cakephp\app>cake bake controller

C:\AppServ\www\cakephp\app>cake bake view

At that time we run the application like :


create a sample table like

CREATE TABLE `users` (

`name` VARCHAR( 255 ) NOT NULL


Use this table for scaffolding.

Then run that file browser like


This is latest stable version of CakePHP.

The screenshot like this :


This is sample code using latest version of using CakePHP.

The manual for CakePHP:



15 Responses

  1. danalakshmi


    Can you explain model associations (hasMany, hasOne, belongsTo, etc.) in easy way? If you will do this means it will be very helpful for all CakePHP beginner.

  2. Pingback : Understanding the basic need of MVC architecture - Anil Labs

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.