应用执行流程:

浏览器向服务器发送 Http Request
|
控制器(protected/controllers)
|
|---> Action
|
创建模型 (Model)
|
检查$_POST输入
|
渲染视图
|
render()第二个参数作为控制器与视图接口参数
|
|----> View (protected/views)
|
使用$this访问控制器的变量(包括layout, widget) -----------------------------------------------------------------

视图渲染流程:

render($view, $data, $return)
|
beforeRender()
|
渲染View文件,调用renderPartial(),要求处理输出结果
|
|----> 根据$view得到viewFile文件名
|
renderFile(),要求返回渲染结果,做下一步处理
|
|-----------> 获取widget的数目
|
从Yii::app()获得render
CWebApplication::getViewRenderer
查询component['viewRenderer'],默认没有配置
|
Then, 调用renderInternal()
|
|---------> require View文件,渲染,根据需要返回渲染结果
|
|<---------------|
|
|<-------------------|
|
处理输出结果processOutput()
|
按照caller参数,返回输出,而不是echo输出
|<--------------|
|
渲染layout文件
| ----------------------------------------------------------------------

加载控制器及其方法:

根据route信息,获得当前控制器
|
初始化当前控制器,CController::init(),默认为空
|
执行当前控制器,CController::run()
|
|----> 创建action,为空则默认为index
|
得到CInlineAction的实例
|
用父对象执行beforeControllerAction:默认是CWebApplication,直接返回TRUE
|
执行action
|----> 备份原来的action
|
执行beforeAction()
|
runWithParams()----> 实际上是执行CInlineAction->runWithParams()
|
在实例中,执行SiteController->actionIndex()
|
渲染页面:render('index')
|
|<--------------------------|
|
执行afterAction()
|
恢复原来action
|
|<----------|
|
用父对象执行afterControllerAction:默认是CWebApplication,为空
|<------------|
完成 ----------------------------------------------------------------

应用执行流程:

index.php
|
require_once($yii)
|
|------------->yii.php
|
require(YiiBase.php)
|
|---------------->YiiBase.php
|
Define YII_XXX global variable
|
Define Class YiiBase
|
Autload Class YiiBase (自动加载类机制)
|
require interface.php
|
|<------------------|
|
define null Class Yii
|
|<--------------|
|
createWebApplication($config)---------->|
|
YiiBase::createApplication('CWebApplication',$config)
|
Create Instance of CWebApplication
|
|--------->CWebApplication
|
CApplication($config)构造函数
|
|------>|
setBasePath
|
set path alias
|
preinit() 空方法
|
initSystemHandlers()
|
configure($config) 将配置文件信息保存到Application
|
attachBehaviors()
|
preloadComponents() --> 装载在configure($config)中配置需要preload的components
|
init() |
|<------|
|
|<------------|
|
|<----------------------------------|
|
app->run()
|
|---->CWebApplication::processRequest()
|
|----> CWebApplication::runController($route)
|
|---->createController($route)
|
如果$route是空,添加默认controller,对于CWebApplication的controller是"site"
|
Controller类是SiteController,require该类文件
|
如果该类是CController的子类,修改id[0]为大写,创建该类的实例
|
|---->CSiteController
|
extends from Controller 这是客户化控制器的基本类,存在于components下
定义了页面的通用布局
|
使用CController构造函数创建对象CSiteController,具体初始化数据见yii-1.png
|
|<--------|
备份$this->_controller
$this->_controller = $controller
|
调用控制器类的init()方法,默认为空
|
调用控制器类的run()方法,默认为CController的run()
|
|---->createAction()
|
if($actionID==='') $actionID设置为$this->default ("index")
|
|Yes
|----> return CInlineAction($this, $actionID)
|No |
从Map创建 |
| 执行当前类CInlineAction的父类CAction的构造函数
| 设置_controller和$id
| |
|<---------------|
|
|
这里得到一个CAction的实例
|
$this->getModule()作为parent,为空则使用Yii::ap
|
$parent->beforeControllerAction() ??
|
$this->runActionWithFilters($action,$this->filters());
|
$parent->afterControllerAction($this,$action);
|<--------|
|
恢复原来的$oldController
|<-----------|
|
|<--------------|
|
End of processRequest()
|
|<-----------------|
|
End of app->run() ------------------------------------------------------------

获取控制器和方法的ID

转载:http://code.dimilow.com/how-to-get-current-controller-name-and-action-name-in-yii/

How to get current controller name and action name in Yii

By Dimi Low on July 7th, 2010 (6 responses)

To get current controller name/id inside your controller, or view
$controllerId = Yii::app()->controller->id;
//or
$controllerId = $this->getId();

To get current action name/id being executed, if you are inside beforeAction() or afterAction(), use the received CAction argument
//inside beforeAction or afterAction
public function beforeAction($action)
{
$actionId = $action->id;
...
or just elsewhere inside your controller
$actionId = $this->getAction()->getId();

----------------------------------------------------

使用YiiMailMessage发送邮件:

安装yii-mail到protected/extension下

配置protected/config/main.php,如下
'import' => array(
......
'application.extensions.yii-mail.*',
),

......
'components' => array(
'mail' => array(
'class' => 'application.extensions.yii-mail.YiiMail',
'transportType' => 'smtp', /// case sensitive!
'transportOptions' => array(
'host' => 'mail.syncomni.com',
'username' => 'huajian@syncomni.com',
// or email@googleappsdomain.com
'password' => 'Sitbwp4m2w',
// 'port' => '465',
// 'encryption' => 'ssl',
),
// 'viewPath' => 'application.views.mail',
'logging' => true,
'dryRun' => false
),
),
发送邮件
// 发送电子邮件
$message = new YiiMailMessage;
$message->setSubject($model->notice_subject);
$message->setBody($model->notice);
$message->setTo('kevin@syncomni.com');
$message->from = Yii::app()->params['adminEmail'];
Yii::app()->mail->send($message);

[转]http://www.cnblogs.com/jinhuawang76/tag/yii/

yii 执行流程的更多相关文章

  1. yii执行流程

    yii执行流程 原文:http://www.cnblogs.com/bluecobra/archive/2011/11/30/2269207.html 一 目录文件 |-framework     框 ...

  2. yii执行流程简单介绍

    1. 用户访问 http://www.example.com/index.php?r=post/show&id=1,Web 服务器执行入口脚本 index.php 来处理该请求.  2. 入口 ...

  3. yii执行原理

    应用执行流程: 浏览器向服务器发送 Http Request | 控制器(protected/controllers) | |---> Action | 创建模型 (Model) | 检查$_P ...

  4. yii2 beta版 执行流程

    yii2 beta版 执行流程 自动加载 1.composer的自动加载 //composer的加载实现了四种方式,可以看看 require(__DIR__ . '/../../vendor/auto ...

  5. Yii2 源码分析 入口文件执行流程

    Yii2 源码分析  入口文件执行流程 1. 入口文件:web/index.php,第12行.(new yii\web\Application($config)->run()) 入口文件主要做4 ...

  6. 步步深入:MySQL架构总览->查询执行流程->SQL解析顺序

    前言: 一直是想知道一条SQL语句是怎么被执行的,它执行的顺序是怎样的,然后查看总结各方资料,就有了下面这一篇博文了. 本文将从MySQL总体架构--->查询执行流程--->语句执行顺序来 ...

  7. 第二天 ci执行流程

    第二天 ci执行流程 welcome 页面 this this->load 单入口框架index.php 两个文件夹 system application定义 定义常亮路径 载入 codeign ...

  8. 轻量级前端MVVM框架avalon - 执行流程2

    接上一章 执行流程1 在这一大堆扫描绑定方法中应该会哪些实现? 首先我们看avalon能帮你做什么? 数据填充,比如表单的一些初始值,切换卡的各个面板的内容({{xxx}},{{xxx|html}}, ...

  9. [Java编程思想-学习笔记]第4章 控制执行流程

    4.1  return 关键字return有两方面的用途:一方面指定一个方法结束时返回一个值:一方面强行在return位置结束整个方法,如下所示: char test(int score) { if ...

随机推荐

  1. iOS 交互h5 - WKWebView

    众所周知,UIWebView存在内存问题,也就是当加载一个UIWebView时,内存会一直上升趋势无法得到释放.这样在使用UIWebView进行h5交互开发时会有很大的问题. 因而苹果增加了一个新的类 ...

  2. Spring系列之——使用了哪些设计模式

    1 工厂模式:BeanFactory.ApplicationContext创建中 2 模板模式:BeanFactory.ApplicationContext实现中 3 代理模式:在AOP实现中用到了J ...

  3. spring boot获取request

    1. Controller中 1.1 通过静态方法获取 HttpServletRequest request = ((ServletRequestAttributes)RequestContextHo ...

  4. 三角形-->九九乘法表

    使用嵌套循环打印九行*组成的三角形: * ** *** ...... *********(9个) public class Triangle { /** * 使用嵌套循环打印九行*组成的三角形 */ ...

  5. vs2017调试源代码

    最近刚入职 ,带我得导师发给我一堆项目,什么云端和医院端,各种wcf服务.window服务和一些公共类库来回调用.搞得是迷迷糊糊,晕头转向.反正是一脸大萌比... 不过经过几个日日夜夜得不停奋战,大致 ...

  6. POJ1321(KB1-A 简单搜索)

    棋盘问题 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 40872 Accepted: 19936 Description 在一 ...

  7. webapi 后台跳转 后台输出html和script

    1.跳转 [HttpGet]public HttpResponseMessage LinkTo(){ HttpResponseMessage resp = new HttpResponseMessag ...

  8. opencv3.2.0图像离散傅里叶变换

    源码: ##名称:离散傅里叶变换 ##平台:QT5.7.1+opencv3.2.0 ##日期:2017年12月13. /**** 新建QT控制台程序****/ #include <QCoreAp ...

  9. memcached 的 SockIOPool 概念

    池的概念 SockIOPool 首先来看下属性 SockIOPool属性 boolean initialized = false – 初始化是否完成的标志,只有初始化完成后上层才能正常使用池 int ...

  10. web 应用响应乱码问题

    非西欧语系乱码原因 在没有设置任何内容类型或编码之前,HttpServletResponse使用的字符编码默认是ISO-8859-1.也就是说,如果直接输出中文,在浏览器上就会看到乱码. 有两种方式可 ...