日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

yii 执行流程

發(fā)布時(shí)間:2025/3/14 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 yii 执行流程 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

應(yīng)用執(zhí)行流程:

瀏覽器向服務(wù)器發(fā)送 Http Request|控制器(protected/controllers)||---> Action|創(chuàng)建模型 (Model)|檢查$_POST輸入|渲染視圖|render()第二個(gè)參數(shù)作為控制器與視圖接口參數(shù)||----> View (protected/views)|使用$this訪問控制器的變量(包括layout, widget)



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

視圖渲染流程:

render($view, $data, $return)| beforeRender()| 渲染View文件,調(diào)用renderPartial(),要求處理輸出結(jié)果||----> 根據(jù)$view得到viewFile文件名|renderFile(),要求返回渲染結(jié)果,做下一步處理||-----------> 獲取widget的數(shù)目|從Yii::app()獲得renderCWebApplication::getViewRenderer查詢component['viewRenderer'],默認(rèn)沒有配置|Then, 調(diào)用renderInternal()||---------> require View文件,渲染,根據(jù)需要返回渲染結(jié)果||<---------------|||<-------------------||處理輸出結(jié)果processOutput()|按照caller參數(shù),返回輸出,而不是echo輸出|<--------------|| 渲染layout文件|

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

加載控制器及其方法:

根據(jù)route信息,獲得當(dāng)前控制器| 初始化當(dāng)前控制器,CController::init(),默認(rèn)為空| 執(zhí)行當(dāng)前控制器,CController::run()||----> 創(chuàng)建action,為空則默認(rèn)為index|得到CInlineAction的實(shí)例|用父對(duì)象執(zhí)行beforeControllerAction:默認(rèn)是CWebApplication,直接返回TRUE|執(zhí)行action|----> 備份原來的action|執(zhí)行beforeAction()|runWithParams()----> 實(shí)際上是執(zhí)行CInlineAction->runWithParams()|在實(shí)例中,執(zhí)行SiteController->actionIndex()|渲染頁面:render('index')||<--------------------------||執(zhí)行afterAction()|恢復(fù)原來action||<----------||用父對(duì)象執(zhí)行afterControllerAction:默認(rèn)是CWebApplication,為空|<------------|完成


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


應(yīng)用執(zhí)行流程:

index.php| require_once($yii)||------------->yii.php|require(YiiBase.php)||---------------->YiiBase.php|Define YII_XXX global variable|Define Class YiiBase|Autload Class YiiBase (自動(dòng)加載類機(jī)制)|require interface.php||<------------------||define null Class Yii||<--------------|| createWebApplication($config)---------->||YiiBase::createApplication('CWebApplication',$config)|Create Instance of CWebApplication||--------->CWebApplication|CApplication($config)構(gòu)造函數(shù)||------>|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是空,添加默認(rèn)controller,對(duì)于CWebApplication的controller是"site"|Controller類是SiteController,require該類文件|如果該類是CController的子類,修改id[0]為大寫,創(chuàng)建該類的實(shí)例||---->CSiteController|extends from Controller 這是客戶化控制器的基本類,存在于components下定義了頁面的通用布局|使用CController構(gòu)造函數(shù)創(chuàng)建對(duì)象CSiteController,具體初始化數(shù)據(jù)見yii-1.png||<--------|備份$this->_controller$this->_controller = $controller|調(diào)用控制器類的init()方法,默認(rèn)為空|調(diào)用控制器類的run()方法,默認(rèn)為CController的run()||---->createAction()|if($actionID==='') $actionID設(shè)置為$this->default ("index")||Yes|----> return CInlineAction($this, $actionID)|No |從Map創(chuàng)建 || 執(zhí)行當(dāng)前類CInlineAction的父類CAction的構(gòu)造函數(shù)| 設(shè)置_controller和$id| ||<---------------|||這里得到一個(gè)CAction的實(shí)例|$this->getModule()作為parent,為空則使用Yii::ap|$parent->beforeControllerAction() ??| $this->runActionWithFilters($action,$this->filters());| $parent->afterControllerAction($this,$action);|<--------||恢復(fù)原來的$oldController|<-----------| ||<--------------||End of processRequest()||<-----------------|| End of app->run()

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


獲取控制器和方法的ID

轉(zhuǎn)載: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發(fā)送郵件:

安裝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
),
),
發(fā)送郵件
// 發(fā)送電子郵件
$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);

?

?

?

[轉(zhuǎn)]http://www.cnblogs.com/jinhuawang76/tag/yii/

轉(zhuǎn)載于:https://www.cnblogs.com/xuan52rock/p/4522558.html

總結(jié)

以上是生活随笔為你收集整理的yii 执行流程的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。