Home  >  Article  >  Backend Development  >  Basics of getting started with cakephp_PHP tutorial

Basics of getting started with cakephp_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:21:05843browse


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 cannot run normally.
2: Direct all requests to the cakephp framework and then enter the framework's route. cakephp comes with a set of default distribution rules (for example: http://.../test/test, without any route configuration In this case, 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 code The code is 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 name of the controller. 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 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 it by default. Table in the database. 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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324969.htmlTechArticleFirst, let’s take a look at the execution process of cakephp (picture borrowed from Baidu Encyclopedia): 1: First, your The server must support rewrite. If it is a virtual host that does not support rewrite, cakephp will not...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn