CakePHP, Cake short, is a program written in PHP open source web framework. CakePHP is based on Ruby on Rails and also follows the scheme of the Model View Controller (MVC ). More common with Ruby on Rails are the underlying principles Do not repeat yourself (DRY) and Convention over configuration.

  • 4.1 Model
  • 4.2 controller
  • 4.3 View
  • 4.4 Similar projects


CakePHP has been developed since 2005. It was parallel to the increasing popularity of Ruby on Rails and the desire for a similar MVC framework for PHP base.

Elimination of lithium

In October 2009, the project manager Garrett Woodworth and developer Nate Abele left the project in order to devote himself lithium, an originally planned as " Cake3 " framework.


CakePHP recognizes as foreign keys in database tables automatically and accordingly generates the correct joins.


Compared to other web frameworks CakePHP provides only low requirements on the web server. It supports PHP version 5.2 and does not require a separate database for the application, but allows you to use database tables with prefixes. Only for the use of so-called Console Applications accessed via the command line is necessary.



The backend is a CakePHP application, a database is used. It supports the following database management systems:

  • MySQL
  • PostgreSQL
  • SQLite
  • Oracle
  • ODBC
  • ADOdb

The so-called model represents the existing data dar. In a user management which works with users and user groups, the user (user) and user groups ( user group ) are the models.

Every model comes with a number of methods which are used for managing the data. For example, there are methods to read from the database ( Model :: read () or Model :: findAllById ()) to store the data in the database (Model :: save () or Model :: save field ()) or to Create a new data set (Model :: create ()). Thus, the CRUD functionality in the models is already integrated.

The relations between different models are defined via so-called Associations ( relationships). Here there are the following options: hasOne, belongsTo, hasMany and hasAndBelongsToMany. CakePHP can generate the required database queries (including any required join commands in SQL) so automatically. Configuration is done through the observance of certain conventions when assigning the names of database tables, models and controllers (see section philosophy). It requires no configuration files.

Models can be extended to Behaviours. It involves classes in which functionality is encapsulated to extend the model. As an example, the Tree Behaviour is: it extends to any model methods that are used to manipulate tree structures. It is said that the model behaves like a tree ( Tree ) - hence the name Behaviour. Behaviours follow the principle Do not repeat yourself, because they can be used in several models.

In model validation information can be stored, will determine what fields may or may not contain. In forms, an error message is displayed automatically then upon validation errors.


The controller contains the so-called Business Logic and provides an interface to interact with the latter. These interfaces are called analogous to Ruby on Rails Actions.

An HTTP request ( for example ) contains the name of the controller and the method to be executed (Action), which are evaluated by the dispatcher and then forwarded to the appropriate controller. It is also possible parameters for the method are passed. The appearance of the URLs is using routes highly customizable.

Controller can be extended with Components in functionality. CakePHP itself contains many components, eg for session management, request handling and safety. Also Access Control Lists can be implemented.

Form data received by the controller from the respective view, can be automatically filtered for malicious code to avoid SQL injections with the " Sanitize ".


Under a view is defined as the presentation layer of a CakePHP application. It acts with a view to a template that is filled by the output data of the respective controller with content. It can be embedded in a template arbitrary PHP code. Views can also be cached.

For recurring expenses in a project, you can rely on the element, which can be thought of as templates within templates.

There are also helper that generate recurring codes, such as HTML forms, JavaScript scripts and code for AJAX communication with the server.

In the development phase can also be dispensed with creating views, by exploiting the scaffolding option in the controller. This dynamic views to manipulate the tables are created.

Similar projects