Beginner cakephp basics _ PHP Tutorial

Source: Internet
Author: User
Basic for cakephp. First, let's take a look at the execution process of cakephp (images borrowed from Baidu Encyclopedia): 1: First, your server must support rewrite. if it is a virtual host that does not support rewrite, cakephp does not
First, let's take a look at the execution process of cakephp (images borrowed from Baidu Encyclopedia ):
1: Your server must support rewrite. cakephp cannot run normally if it is a virtual host that does not support rewrite.
2: after all requests are directed to the cakephp framework, they enter the route of the framework. cakephp has a set of default distribution rules (for example, http ://...... /Test. cakephp automatically runs the test method in the test_controller controller without any route configuration ).
We can direct any request to the controller and method we want to execute by configuring route. the configuration is as follows (app/config/routes. php ):

The code is as follows:


Router: connect ('/pages/*', array ('controller' => 'test', 'Action' => 'index '));


3: After the request enters the controller, cakephp loads the default model according to the controller name. For example, TestController automatically loads the test. php file under models. then we can call the model method using the following method.

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 cake \ libs \ controller. php)

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 the models in the uses array will be instantiated.
4, 5, 6: a process in which the controller and model directly process the business logic. it is worth noting that the model of cakephp is inherited from the AppModel, some database operation methods have been implemented in the AppModel, and the model will be associated with tables in the database by default. This is not very good. The model is just a database operation layer.
7: After processing the business, the data must be integrated with html and output to the browser end. The cakephp view contains layout files, element files, and template files. these files are suffixed with ctp in version 1.3. you can modify var $ ext = 'in the controller base class '. to change the suffix of the template file.
Conclusion: The cakephp framework is not flexible enough, and the model layer has limitations. In view files, php syntax is used to facilitate task separation during team development. Cakephp is easy to use in small projects. the scaffolding, core components, and classes provided by the framework can quickly and conveniently build a project. Cakephp was first recognized, and there may be deviations.

Slave (image 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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.