|developer||Cake Software Foundation|
(December 15, 2019)
|operating system||platform independent|
CakePHP , or Cake for short , is an open source web framework written in PHP . CakePHP is based on Ruby on Rails and also follows the scheme of the Model View Controller (MVC). Other similarities with Ruby on Rails are the underlying principles Don't repeat yourself (DRY) and convention before configuration .
CakePHP has been in development since 2005. It was created parallel to the increasing popularity of Ruby on Rails and the desire for a similar MVC framework based on PHP.
Separation of lithium
In October 2009 the project manager Garrett Woodworth and developer Nate Abele left the project to devote themselves to lithium , a framework originally planned as "Cake3".
Analogous to Ruby on Rails , CakePHP tries to keep the configuration to a minimum. This means that the only configuration step is to define the connection parameters to the database server. The assignment of z. B. Models for database tables are made using the same names in singular and plural, not using configuration files. This principle is known as Convention over Configuration (CoC). Example:
- User , Group (Singular)
- UsersController , GroupsController (plural)
- Database table
- users , groups , groups_users (plural, the last example shows the name for a relation table for hasAndBelongsToMany. In this case, the tables to be linked are specified in alphabetical order)
- Foreign keys in database tables
- user_id , group_id (singular plus _id )
CakePHP, for example, automatically recognizes foreign keys in database tables and generates the correct joins accordingly .
Compared to other web frameworks, CakePHP makes only minor demands on the web server. From CakePHP 3 PHP 5.4.16 or higher is required. It does not require a separate database for the application, but allows database tables with prefixes to be used. Access to the command line is necessary when using so-called console applications .
A database is used as the backend of a CakePHP application. The following database management systems are supported:
The so-called model represents the existing data. In a user administration, which works with users and user groups, the users ( user ) and user groups ( usergroup ) are the models.
Each model brings a number of methods that are used to manage the data. For example, there are methods for reading from the database ( Model :: read () or Model :: findAllById () ), for saving the data in the database ( Model :: save () or Model :: saveField () ) or for Create a new data set ( Model :: create () ). Thus, the CRUD functionality is already integrated in the models.
The relationships between different models are determined by so-called associations . The following options exist: hasOne, belongsTo, hasMany and hasAndBelongsToMany. CakePHP can automatically generate the required database queries (including any join commands required in SQL). The configuration is done by observing certain conventions when assigning the names of database tables, models and controllers (see section Philosophy ). No configuration files are required.
Models can be expanded to include behaviors . These are classes in which functionality for extending the model is encapsulated. The tree behavior serves as an example : it expands any model with methods that are used to manipulate tree structures. It is said that the model behaves like a tree ( Tree ) - hence the name Behavior. Behaviors follow the don't repeat yourself principle , as they can be used in multiple models.
Validation information can be stored in models that determine what fields may or may not contain. An error message is then automatically displayed in forms in the event of validation errors.
The controller contains the so-called business logic and offers interfaces to interact with it. These interfaces are called Actions , analogous to Ruby on Rails .
An HTTP request (for example
http://example.org/controller/action/parameter) contains the name of the controller and the method to be executed (action), which are evaluated by the dispatcher and then forwarded to the corresponding controller. Parameters for the method can also be passed. The appearance of the URLs can be adapted very flexibly with the help of routes .
Controllers can be expanded in their functionality with components . CakePHP itself contains many components, e.g. B. for session management, request handling and security. Also, access control lists can be realized.
A view is the presentation layer of a CakePHP application. A view is a template that is filled with content by the output data of the respective controller. Any PHP code can be embedded in a template. Views can also also cached are.
For repetitive expenses in a project, you can fall back on elements , which you can imagine as templates within templates.
The creation of views can also be dispensed with in the development phase by using the scaffolding option in the controller. Views are created dynamically to manipulate the tables.
- Lithium Framework
- eZ Components
- PHP on Trax
- Zend Framework
- Fusca RefactorPHP
- Dirk Ammelburger, Robert Scherer: Web development with CakePHP . O'Reilly, ISBN 3-89721-863-1
- David Golding: Beginning CakePHP: From Novice to Professional . Apress, ISBN 1-4302-0977-1 (English)
- Ahsanul Bari, Anupom Syam: CakePHP Application Development: Step-by-step introduction to rapid web development using the open-source MVC CakePHP framework . Packt Publishing, ISBN 978-1-84719-389-6 (English)
- [de.wikipedia.org] Current release. Retrieved December 26, 2019.