search
Homephp教程php手册Cakephp 执行主要流程

Cakephp执行主要流程,学习cakephp的朋友可以参考下。

加载基本文件
cake/basics.php 里面定义了常用的方法以及时间常量
$TIME_START = getMicrotime(); 记录开始执行时间
cake/config/paths.php 里面定义一些基本路径
cake/lib/object.php cake的基本类
cake/lib/inflector.php 这里主要是处理单复数,带下划开命名以及驼峰式命名
cake/lib/configure.php 里面提供文件配置的读写,路径的设置,以及加载文件的方法
cake/lib/cache.php 缓存的操作

Configure::getInstance(); 开始对项目的配置
config/core.php 项目的配置文件
config/bootstrap.php 项目的入口文件

App::import(‘Core', array(‘Dispatcher')); 加载核心,开始做正事了,GO
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch($url); 开始执行,通过对当前的url解析,如果你设置了压缩Js、Css,则对这些文件压缩输出,如果你对页面设置缓存,则直接输出缓存页面,最后查找相应的Controller。如果找不到,则进行相应的错误处理。
实例化当前Controller,确定视图路径,实例化Component,获得仅当前Controller[不包含父类Controller]的方法
对当前Controller中私有方法、带admin路由或者带prefix的方法进行保护,不允许直接访问
设置当前Controller的基本属性,如base、here、webroot、plugin、params、action、 passedArgs[array_merge($this->params['pass'],$this->params['named'])]
调用Controller中的constructClasses方法
执行__mergeVars方法,该方法对父子类的components、helpers、uses等属性进行特殊合并处理
调用Component->init()方法,载入用户设置的系列components(Session为默认),并默认enabled属性为true。(该属性可以后期在beforeFilter里修改)
调用Component->initialize()方法,若系列components里有这个initialize方法并且该component 的enabled为true,则调用该components->initialize方法(这里enabled用户好像无法通过 Controller设置,只能为true)
调用当前Controller中beforeFilter()方法,这个方法是个好东西^_^
调用Component->startup()方法,同样,若系列components里有这个startup方法并且该component的 enabled为true,则调用该components->startup方法(这里enabled倒是可以通过beforeFilter设 置),该方法也是components里最重要的方法,比如Auth就在这里大作文章^_^
开始执行当前Controller里的Action方法
如果设置autoRender为true,则根据调用当前Controller的render()方法,否则返回或输出Action方法的返回的数据
调用Controller的render()方法时,先调用当前Controller中的beforeRender()方法
加载视图渲染类
调用Component->beforeRender()方法,同样,若系列components里有这个beforeRender方法并且该 component的enabled为true,则调用该components->beforeRender方法(这里enabled可以通过 beforeFilter设置)
获取当前Model的数据验证错误信息,给View使用
调用View的render()方法
载入相关Helper助手
调用Helper的beforeRender()方法
调用Helper的afterRender()方法
相关的缓存处理
执行renderLayout()方法,当然前提你要允许渲染布局,默认为default.ctp布局文件
调用Helper的beforeLayout()方法
调用Helper的afterLayout()方法
调用Component->shutdown()方法,同样,若系列components里有这个shutdown方法并且该component的 enabled为true,则调用该components->shutdown方法(这里enabled可以通过beforeFilter设置)
执行当前Controller里的afterFilter方法,这里你可以对视图的输出内容($controller->output)做一些处理
返回或输出视图数据。
流程完毕。
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
如何使用CakePHP中的数据库查询构造器?如何使用CakePHP中的数据库查询构造器?Jun 04, 2023 am 09:02 AM

CakePHP是一个开源的PHPMVC框架,它广泛用于Web应用程序的开发。CakePHP具有许多功能和工具,其中包括一个强大的数据库查询构造器,用于交互性能数据库。该查询构造器允许您使用面向对象的语法执行SQL查询,而不必编写繁琐的SQL语句。本文将介绍如何使用CakePHP中的数据库查询构造器。建立数据库连接在使用数据库查询构造器之前,您首先需要在Ca

如何在CakePHP中创建自定义分页?如何在CakePHP中创建自定义分页?Jun 04, 2023 am 08:32 AM

CakePHP是一个强大的PHP框架,为开发人员提供了很多有用的工具和功能。其中之一是分页,它可以帮助我们将大量数据分成几页,从而简化浏览和操作。默认情况下,CakePHP提供了一些基本的分页方法,但有时你可能需要创建一些自定义的分页方法。这篇文章将向您展示如何在CakePHP中创建自定义分页。步骤1:创建自定义分页类首先,我们需要创建一个自定义分页类。这个

如何使用PHP和CakePHP框架进行应用程序开发如何使用PHP和CakePHP框架进行应用程序开发May 11, 2023 pm 03:39 PM

在当今数字化时代,应用程序对于企业和个人来说,已经成为了不可或缺的一部分。应用程序能够让人们更加便捷地进行各种操作,而PHP和CakePHP框架则是日益流行的应用程序开发工具。在本文中,我们将讨论如何使用PHP和CakePHP框架进行应用程序开发。一、PHP是什么?PHP(外文全称为“HypertextPreprocessor”)是一种开源的服务器端脚本语

如何在CakePHP中使用FPDF?如何在CakePHP中使用FPDF?Jun 03, 2023 pm 06:32 PM

CakePHP是一种流行的PHP框架,用于开发Web应用程序。与许多其他PHP框架一样,CakePHP也提供了许多有用的功能和插件来帮助业务流程,其中包括生成PDF文件。这项任务可以使用FPDF插件轻松完成。本文将介绍如何在CakePHP中使用FPDF。FPDF是一种开源的PHP类库,用于生成PDF文件。它具有许多有用的功能,例如嵌入字体、添加图像、绘制基本

如何在CakePHP中进行数据查询和更新?如何在CakePHP中进行数据查询和更新?Jun 03, 2023 pm 02:11 PM

CakePHP是一个流行的PHP框架,它提供了方便的ORM(对象关系映射)功能,使得查询和更新数据库变得非常容易。本文将介绍如何在CakePHP中进行数据查询和更新。我们将从简单的查询和更新开始,逐步深入,了解如何使用条件和关联的模型来更复杂地查询和更新数据。基本查询首先,让我们看看如何进行最简单的查询。假设我们有一个名为“Users”的数据表,并且我们想要

如何在CakePHP中使用Guzzle?如何在CakePHP中使用Guzzle?Jun 03, 2023 pm 01:51 PM

CakePHP是一款优秀的PHP开发框架,它通过提供一系列强大的功能和工具,简化了Web应用程序的开发过程。而Guzzle是一个PHPHTTP客户端和请求库,它能够帮助开发者轻松地发送HTTP请求和访问Web服务。在本文中,我们将介绍如何在CakePHP中使用Guzzle,以便更加高效地开发Web应用程序。一、安装Guzzle首先,我们需要在CakePHP

如何在CakePHP中使用多个数据库连接?如何在CakePHP中使用多个数据库连接?Jun 04, 2023 am 08:21 AM

CakePHP是一款流行的PHP开发框架,它提供了快速开发Web应用程序所需的基本功能和结构。在现代应用中,使用多个数据库连接已经成为了一个普遍的需求,例如,建立主从数据库连接或将数据分片到不同的数据库中。本文将介绍如何在CakePHP中使用多个数据库连接。CakePHP中的默认数据库连接在开始之前,让我们先了解一下CakePHP中默认的数据库连接。Cake

如何使用CakePHP中的Cookie组件?如何使用CakePHP中的Cookie组件?Jun 03, 2023 pm 06:31 PM

CakePHP是一款流行的PHP框架,它为Web开发提供了许多便利的功能。其中一个非常有用的功能是Cookie组件。在本文中,我们将介绍如何在CakePHP中使用Cookie组件来存储和检索数据。一、什么是Cookie?Cookie是一个小的数据片段,存储在网站上的用户计算机上。它可以用来存储用户喜好、登陆信息和其他相关的数据。Cookie可以被服务器和客户

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),