The basics of CakePHP's first product, cakephp

Source: Internet
Author: User

First look at CakePHP's implementation process (from Baidu Encyclopedia borrowed Pictures):
1: First your server must support rewrite, if it is not supported rewrite virtual host, cakephp will not work properly.
2: After all requests are directed to the cakephp framework, the route,cakephp comes into the framework with a set of default distribution rules (for example: Http://....../test/test, cakephp automatically executes without any route configuration Test_ The test method in the controller control).
We can configure the route to point any request to the controller and method we want to execute, configured as follows (app/config/routes.php):

Copy the Code code as follows:


Router::connect ('/pages/* ', Array (' controller ' = ' test ', ' action ' = ' index ');


3: After the request enters the controller, cakephp will load the default model according to the controller's name. For example: TestController will automatically load the test.php file under models, and then we can invoke the model method by the following method.

Copy the Code code as follows:


$this->test->find (' all ');


View the Controller base class source for the cakephp framework (cake\libs\controller\controller.php in the __mergevars method)

Copy the 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}));
}
}
}


When cakephp constructs a controller, the model in the uses array is all instantiated.
4, 5, 6: Is the controller and model directly handle the business logic of a process, it is noteworthy that cakephp model inherited from Appmodel, in the Appmodel has implemented a number of database operation methods, And the model is associated to a table in the database by default. This is not a good feeling, model is just a database operation layer.
7: After the business processing, the final data to be consolidated HTML output to the browser side. In the CakePHP view contains layout files, element files and template files, these files in version 1.3 with the CTP suffix, in the controller base class can be modified var $ext = '. CTP '; To change the suffix of the template file.
Summary: The cakephp framework does not feel flexible enough to use, and the model layer has limitations. In the view file, PHP syntax is not easy to separate tasks in team development. CakePHP still has a lot to do with small projects, and scaffolding, core components, and classes provided by the framework can build a project quickly and easily. There may be deviations from CakePHP's initial knowledge.

This article introduces CakePHP's primer on cakephp, including CakePHP's content, hoping to be helpful to a friend who is interested in PHP tutorials.

  • Related Article

    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.