Structure of CakePHP

Facebooktwitterredditpinterestlinkedinmailby feather

Overview of MVC 

Model-view-controller

It is a pattern in software design that allows you to differentiate the code logically, make it more reusable, maintainable, and generally better.

Model

In Cake Terms, the model represents a specific database table/record, and its relationship to other tables and files. The model also has rules to validate your data that implement the inserted or updated operation in your database table. Handles all data processing, validation, and association that related to the data

View

It works as a Presentation layer that displays the information in such a way that can be beneficial for the user. What to end-user sees on the web browser.

Controller

It interacts with the model and view to deliver a response to the user. The controller handles the requested data, ensuring that the correct model is called and the proper response or view is provided.

Structure of CakePHP

You can see the folder structure of CakePHP, described below.

Structure of CakePHP

Folder Name & Description

Bin

The bin folder contains the Cake console executables files.

Config

The config folder contains some configuration files for CakePHP uses. Database connection details, route files, bootstrapping, core configuration files, and more.

Logs

The log folder usually holds some log files of your application based on the log configuration.

Plugins

A CakePHP plugin which is used for providing additional functionality in your application. You can also reuse it in other applications of CakePHP.

Src

The src folder contains the MVC files of your application. In this folder, you will put your CakePHP files for the development of web applications.  Now, take a look at the src files in brief.

  1. The console holds the console command prompt for running your application file.
  2. A Controller that holds the controller’s files and their components too.
  3. The locale contains string files for internationalization.
  4. A model that is used for connecting with the database table, so it holds the application’s tables, entities, and behavior.
  5. The view is a presentational class that placed in cells, helpers, and template files, which can call in the controller file.
  6. A template is also a presentational file that put in element, error pages, layout, and view template files

Tests

The test folder which contains the test cases of your application.

Tmp

Tmp is a folder of CakePHP in which it stores the temporary file, and the actual data depends on the configuration of CakePHP. This folder is used for storing the model data, and sometimes it can store session information.   

Vendor

The vendor is a folder of CakePHP in which it holds the dependencies of CakePHP and other applications. So, we can’t edit these files, and if you changed by mistakes, then the composer will overwrite your previous record.

Webroot

The webroot is a folder of CakePHP in which it contains all the public document which you want to fetch in your helper class like jpg, CSS, javascript file.

CakePHP Request Cycle

A CakePHP request cycle begins with a user-requested page in your application program. At each stage of the application, the user-requests are passed one by one.

CakePHP Request Cycle
CakePHP Request Cycle
  1. Suppose a client request for a particular item on the web browser. Then the request carried out by the dispatcher. Example: suppose a user wants to fill his examination fee online. The dispatcher, filter the client request from the number of applications on the server, send their request for a particular web server. 
  2. Dispatcher filters or select only the routes that have been requested by the client that can be configured and handle the request.
  3. A large number of routes are determined for the request in the respective controller and take action based on routing rules.
  4. Then the controller’s action is implemented, and the controller interacts with the required model and components. It takes dynamic data from the model that is relevant to the request. Example When you fill the contact_us / feedback page in your web application, the model stores the details in the format of the data source and behavior. We can also identify from which website we have collected the details
  5. The controller can check dependencies from component and database models, send feedback to the view.
  6. CakePHP uses a view helper and element to generate a responsive body.
  7. And finally, the requested page will show to the user web browser.
Facebooktwitterredditpinterestlinkedinmailby feather