cakephp first cakephp entry basics
Jul 29, 2016 am 08:47 AM
First, let’s take a look at the execution process of cakephp (picture borrowed from Baidu Encyclopedia):
1: First, your server must support rewrite. If it is a virtual host that does not support rewrite, cakephp will not run normally.
2: After directing all requests to the cakephp framework, you enter the framework's route. cakephp comes with a set of default distribution rules (for example: http://.../test/test, without any route configuration cakephp will automatically execute the test method in the test_controller controller).
We can direct any request to the controller and method we want to execute by configuring the route. The configuration is as follows (app/config/routes.php):
Copy the code The code is as follows:
Router: :connect('/pages/*', array('controller' => 'test', 'action' => 'index'));
3: After the request enters the controller, cakephp will go to the controller according to the name of the controller. Load the default model. For example: TestController will automatically load the test.php file under models, and then we can call the method of the model through the following method.
Copy the code The code is as follows:
$this->test->find('all');
View the controller base class source code of the cakephp framework (in the __mergeVars method of cakelibscontrollercontroller.php )
Copy the code The code is as follows:
if ($this->uses !== null && $this->uses !== false) {
$merge[] = 'uses';
}
foreach ($merge as $var) {
if (isset($appVars[$var]) && !empty($appVars[$var]) && is_array($this->{$var})) {
if ($var !== 'uses') {
$normal = Set::normalize($this->{$var});
$app = Set::normalize($appVars[$var]);
if ($app !== $normal) {
$this->{$var} = Set::merge($app, $normal);
}
} else {
$this->{$var } = array_merge($this->{$var}, array_diff($appVars[$var], $this->{$var}));
}
}
}
When cakephp constructs the controller All models in the uses array will be instantiated.
4, 5, 6: It is a process in which the controller and model directly handle business logic. It is worth noting that cakephp’s model inherits from AppModel. Some database operation methods have been implemented in AppModel, and the model will be associated with the database by default. table. This doesn't feel very good. The model is just an operation layer of the database.
7: After completing the business processing, the final data must be integrated into HTML and output to the browser. The view of cakephp contains layout files, element files and template files. These files adopt the suffix of ctp in version 1.3. In the controller base class, you can modify var $ext = '.ctp'; to change the suffix of the template file.
Summary: The cakephp framework feels not flexible enough to use, and the model layer has limitations. The syntax used in the view file is PHP, which is not convenient for task separation in team development. Cakephp is quite capable in small projects. The scaffolding, core components and some classes provided by the framework can quickly and easily build a project. I am new to cakephp, so my understanding may be biased.
The above introduces the basics of getting started with cakephp, the first version of cakephp, including the content of cakephp. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Validator can be created by adding the following two lines in the controller.

This chapter deals with the information about the authentication process available in CakePHP.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is a powerful PHP framework that provides developers with many useful tools and features. One of them is pagination, which helps us divide large amounts of data into several pages, making browsing and manipulation easier. By default, CakePHP provides some basic pagination methods, but sometimes you may need to create some custom pagination methods. This article will show you how to create custom pagination in CakePHP. Step 1: Create a custom pagination class First, we need to create a custom pagination class. this

To work on file upload we are going to use the form helper. Here, is an example for file upload.
