First look at the cake's implementation process (from the Baidu Encyclopedia borrowed Pictures):
1: First of all, your server must support rewrite, if it is not support rewrite virtual host words cake is not normal operation.
2: After all requests are directed to the cake frame, the route,cakephp comes into the frame with a set of default distribution rules (for example: Http://....../test/test, which is automatically executed without any route configuration) test_ The test method in the controller controller).
We can configure route to point any request to the Controller and method that we want to execute, configured as follows (app/config/routes.php):
Copy Code code as follows:
Router::connect ('/pages/* ', Array (' controller ' => ' test ', ' action ' => ' Index '));
3: After the request enters the controller, the cake will load the default model according to Controller's name. For example: TestController will automatically load the test.php file under models, and then we can call the model method in the following ways.
Copy Code code as follows:
$this->test->find (' all ');
View the controller base source (cake\libs\controller\controller.php __mergevars method) of the cake framework
Copy Code code 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}));
}
}
}
the model in the uses array is instantiated when the cake is constructed controller.
4, 5, 6: Controller and model directly deal with the business logic of a process, it is worth noting that cake model inherits from Appmodel, in Appmodel has implemented some database operation methods, and model will default to the tables in the database. This feeling is not very good, model is just a database of the operating layer.
7: After the business process, the final data to be consolidated HTML output to the browser side. The cake view contains layout files, element files, and template files, which use the CTP suffix in version 1.3, and the var $ext = '. CTP ' can be modified in the Controller base class to change the suffix of the template file.
Summary: Cake frame is not flexible to use, the model layer has limitations. In the view file, PHP syntax is not easy to separate tasks in team development. In small projects, cake is still a good team, the framework provides scaffolding, core components and some classes can quickly and easily build a project. The first knowledge of cake may be biased.