Recently, the project was quite easy. I just had time to get to know about cakephp. The following is just a glimpse of cakephp, which does not guarantee the correctness of the content.
Recently, the project was quite easy. I just had time to get to know about cakephp. The following is just a glimpse of cakephp, which does not guarantee the correctness of the content.
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.