Detailed explanation of Yii2.0 execution process
This article mainly shares with you the detailed explanation of Yii2.0 execution process, mainly in the form of code, hoping to help everyone.
index.php 2 ---->引入 vendor/auto_load.php 3 auto_load.php 4 ---->引入 ventor/composer/autoload_real.php 5 ---->执行 ComposerAutoloaderInit240f916b39e20bc11bc03e2039805bd4->getLoader 6 autoload_real.php 7 ---->getLoader 8 ---->单例 9 ---->spl_autoload_register(array('ComposerAutoloaderInit240f916b39e20bc11bc03e2039805bd4','loadClassLoader')) 10 ---->self::$loader = new \Composer\Autoload\ClassLoader(); 11 ---->引入 \Composer\Autoload\ClassLoader 12 ---->引入 autoload_namespaces.php 给作为属性 $loader 13 ---->$vendorDir $baseDir 14 ---->引入 autoload_psr4.php 作为属性给 $loader 15 ---->$loader->register(true); 16 ---->spl_autoload_register this,loadClass 17 ---->loadClass ----> findFile 18 ---->引入 autoload_files.php require 19 ---->return $loader 20 index.php 21 ---->初始化了一个$loader (暂时不知道什么用) 22 ---->引入 /vendor/yiisoft/yii2/Yii.php 23 Yii.php 24 ----> 引入 BaseYii.php ,Yii 继承 BaseYii 25 ---->spl_autoload_register(BaseYii,autoload) 26 ---->Yii::$classMap = include(__DIR__ . '/classes.php'); //引入一堆php class地址 27 ---->Yii::$container = new yii\di\Container;//容器 28 29 //继承关系梳理 30 yii\di\Container(容器) -> yii\base\Component(实现 属性,事件,行为 功能的基类) -> Object(实现 属性 功能的基类,含有__construct) 31 yii\web\Application(所有web应用类的基类) -> \yii\base\Application(所有应用的基类,__construct) -> Module(所有模块和应用的基类,含有__construct) -> yii\di\ServiceLocator(服务定位器,包含所有模块和应用) -> yii\base\Component -> Object 32 33 index.php 34 ---->$config 引入 35 (new yii\web\Application($config))->run(); 36 ---->\yii\base\Application __construct() 37 ---->Yii::$app = $this (Application) 38 ---->$this->setInstance($this); 设置当前请求类的实例 (把Application类的对象push进Yii的loadedModules里) 39 ---->$this->preInit($config); 40 ---->$this->_basePath = $_config['basepath'] Yii::aliases[@app] = $_config['basepath'] 41 ---->$this->getVendorPath 设置框架路径 42 ---->setVendorPath Yii::aliases[@vendor] Yii::aliases[@bower] Yii::aliases[@npm] 43 ---->$this->getRuntimePath 同上,设置runtimePath Yii::aliases[@runtime] 44 ---->setTimeZone 设置时区 45 ---->核心组件信息(地址)注入$config log view formatter i18n mailer urlManager assetManager security 46 ---->registerErrorHandler 定义错误处理程序 47 ---->Component::__construct($config); Object中的__construct //这步发生了很多事情 48 ---->Yii::configure($this) 把$config赋给$this作属性 49 50 ? $this->bootstrap 中的值哪来的 ?---->配置文件来的。。。。 51 52 ---->$this->init() 53 ---->$this->bootstrap(); 初始化扩展和执行引导组件。 54 ---->引入@vendor/yiisoft/extensions.php 55 ---->Yii::aliases['xxx'] = 'xxx'; extensions.php中aliase地址 56 <!-- 初始化完成 --> 57 58 ---->\yii\base\Application->run() 59 ---->$this->trigger($name) --- $event = new Event; //$name = beforeRequest 执行 _event[beforeRequest]handler 60 ---->$event->sender = application object 61 $event->name = $name; 62 //这两句没懂 63 $event->data = $handler[1]; 64 call_user_func($handler[0], $event); 65 Event::trigger($this, $name, $event); //$this = application object 66 67 ---->$response = $this->handleRequest($this->getRequest()); 68 ---->$this->getRequest() ---->get('request') get方法位于ServiceLocator ,返回指定id的实例(返回request实例到_components['request']) 69 ---->$this->handleRequest(request对象) //request对象的类是yii/web/request 70 ---->list ($route, $params) = $request->resolve();//解决当前请求的路由和相关参数 71 ---->$params 放置地址栏解析的结果数组Array ( [0] => [1] => Array ( [m] => sds [c] => dasd ) ) 72 ---->runAction($route, $params); //位于Module 73 ---->list($controller, $actionID) = $this->createController($route) 返回array('0'=>控制器controller对象,'1'=>'action名') 74 $controller 赋给Yii::$app->controller 75 ---->$controller->runAction($actionID, $params); yii/base/Controller 76 77 ---->runAction($actionID, $params); yii/base/Controller 78 ---->$action = $this->createAction($id); //生成一个InlineAction对象,赋给Yii::$app->requestedAction 79 InlineAction __construct $this->actionMethod = $actionMethod; 80 ---->beforeAction 81 ---->$action->runWithParams($params); //位于 yii/base/InlineAction 82 ---->$args = $this->controller->bindActionParams($this, $params);//位于yii/web/controller $this=>InlineAction $params=>模块/控制器 数组 --- 将参数绑定到action,返回有效参数数组$args 83 ---->赋给Yii::$app->requestedParams = $args; 84 ---->call_user_func_array([$this->controller, $this->actionMethod], $args) //执行第一个回调函数 真正执行 85 ---->afterAction 86 ---->返回执行结果(页面已出) 给Module中的runAction 87 88 ---->返回结果给handleRequest 89 ---->$response = $this->getResponse(); 返回一个response对象,具体同上 90 ---->$response->data = $result; 91 ---->返回$response给yii/base/Application 的 run $response 92 ---->$response->send();输出内容 93 <!-- 页面输出完成 --> 94 95 96
The above is the detailed content of Detailed explanation of Yii2.0 execution process. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Automation and task scheduling play a vital role in streamlining repetitive tasks in software development. Imagine there is a Python script that needs to be executed every 5 minutes, such as getting data from an API, performing data processing, or sending periodic updates. Running scripts manually so frequently can be time-consuming and error-prone. This is where task scheduling comes in. In this blog post, we will explore how to schedule a Python script to execute every 5 minutes, ensuring it runs automatically without manual intervention. We will discuss different methods and libraries that can be used to achieve this goal, allowing you to automate tasks efficiently. An easy way to run a Python script every 5 minutes using the time.sleep() function is to utilize tim

Windows operating system is one of the most popular operating systems in the world, and its new version Win11 has attracted much attention. In the Win11 system, obtaining administrator rights is an important operation. Administrator rights allow users to perform more operations and settings on the system. This article will introduce in detail how to obtain administrator permissions in Win11 system and how to effectively manage permissions. In the Win11 system, administrator rights are divided into two types: local administrator and domain administrator. A local administrator has full administrative rights to the local computer

Detailed explanation of the mode function in C++ In statistics, the mode refers to the value that appears most frequently in a set of data. In C++ language, we can find the mode in any set of data by writing a mode function. The mode function can be implemented in many different ways, two of the commonly used methods will be introduced in detail below. The first method is to use a hash table to count the number of occurrences of each number. First, we need to define a hash table with each number as the key and the number of occurrences as the value. Then, for a given data set, we run

Detailed explanation of division operation in OracleSQL In OracleSQL, division operation is a common and important mathematical operation, used to calculate the result of dividing two numbers. Division is often used in database queries, so understanding the division operation and its usage in OracleSQL is one of the essential skills for database developers. This article will discuss the relevant knowledge of division operations in OracleSQL in detail and provide specific code examples for readers' reference. 1. Division operation in OracleSQL

How to use Python to write and execute scripts in Linux In the Linux operating system, we can use Python to write and execute various scripts. Python is a concise and powerful programming language that provides a wealth of libraries and tools to make scripting easier and more efficient. Below we will introduce the basic steps of how to use Python for script writing and execution in Linux, and provide some specific code examples to help you better understand and use it. Install Python

Detailed explanation of the remainder function in C++ In C++, the remainder operator (%) is used to calculate the remainder of the division of two numbers. It is a binary operator whose operands can be any integer type (including char, short, int, long, etc.) or a floating-point number type (such as float, double). The remainder operator returns a result with the same sign as the dividend. For example, for the remainder operation of integers, we can use the following code to implement: inta=10;intb=3;

The modulo operator (%) in PHP is used to obtain the remainder of the division of two numbers. In this article, we will discuss the role and usage of the modulo operator in detail, and provide specific code examples to help readers better understand. 1. The role of the modulo operator In mathematics, when we divide an integer by another integer, we get a quotient and a remainder. For example, when we divide 10 by 3, the quotient is 3 and the remainder is 1. The modulo operator is used to obtain this remainder. 2. Usage of the modulo operator In PHP, use the % symbol to represent the modulus

Detailed explanation of Linux system call system() function System call is a very important part of the Linux operating system. It provides a way to interact with the system kernel. Among them, the system() function is one of the commonly used system call functions. This article will introduce the use of the system() function in detail and provide corresponding code examples. Basic Concepts of System Calls System calls are a way for user programs to interact with the operating system kernel. User programs request the operating system by calling system call functions
