Yii Framework v1.1.10 绫诲弬鑰

CAction

system.web.actions
缁ф壙 abstract class CAction » CComponent
瀹炵幇 IAction
瀛愮被 CCaptchaAction, CInlineAction, CViewAction, CWebServiceAction
婧愯嚜 1.0
鐗堟湰 $Id: CAction.php 3426 2011-10-25 00:01:09Z alexander.makarow $
婧愮爜 framework/web/actions/CAction.php
CAction鏄墍鏈夋帶鍒跺櫒鍔ㄤ綔绫荤殑鍩虹被銆

CAction鐢ㄥ垎寮鐨勭被鏂囦欢鎻愪緵浜嗕竴涓垎鍓蹭竴涓鏉傜殑鎺у埗鍣 鍒板嚑涓畝鍗曠殑鍔ㄤ綔鐨勯斿緞銆

娲剧敓绫诲繀椤诲疄鐜皉un()鏂规硶锛 褰揳ction琚姹傛椂鐢眂ontroller鍙戣捣銆

涓涓猘ction瀹炰緥鑳介氳繃controller灞炴ц闂畠鐨勬帶鍒跺櫒銆

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
controller CController 鎷ユ湁杩欎釜鍔ㄤ綔鐨勬帶鍒跺櫒銆 CAction
id string 鍔ㄤ綔鐨処D銆 CAction

鍏叡鏂规硶

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
__call() 濡傛灉绫讳腑娌℃湁璋冪殑鏂规硶鍚嶏紝鍒欒皟鐢ㄨ繖涓柟娉曘 CComponent
__construct() 鏋勯犳柟娉曘 CAction
__get() 杩斿洖涓涓睘鎬у笺佷竴涓簨浠跺鐞嗙▼搴忓垪琛ㄦ垨涓涓涓哄悕绉般 CComponent
__isset() 妫鏌ヤ竴涓睘鎬ф槸鍚︿负null銆 CComponent
__set() 璁剧疆涓涓粍浠剁殑灞炴у笺 CComponent
__unset() 璁剧疆涓涓粍浠剁殑灞炴т负null銆 CComponent
asa() 杩斿洖杩欎釜鍚嶅瓧鐨勮涓哄璞° CComponent
attachBehavior() 闄勫姞涓涓涓哄埌缁勪欢銆 CComponent
attachBehaviors() 闄勫姞涓涓涓哄垪琛ㄥ埌缁勪欢銆 CComponent
attachEventHandler() 涓轰簨浠堕檮鍔犱竴涓簨浠跺鐞嗙▼搴忋 CComponent
canGetProperty() 纭畾灞炴ф槸鍚﹀彲璇汇 CComponent
canSetProperty() 纭畾灞炴ф槸鍚﹀彲鍐欍 CComponent
detachBehavior() 浠庣粍浠朵腑鍒嗙涓涓涓恒 CComponent
detachBehaviors() 浠庣粍浠朵腑鍒嗙鎵鏈夎涓恒 CComponent
detachEventHandler() 鍒嗙涓涓瓨鍦ㄧ殑浜嬩欢澶勭悊绋嬪簭銆 CComponent
disableBehavior() 绂佺敤涓涓檮鍔犺涓恒 CComponent
disableBehaviors() 绂佺敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
enableBehavior() 鍚敤涓涓檮鍔犺涓恒 CComponent
enableBehaviors() 鍚敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
evaluateExpression() 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 CComponent
getController() 杩斿洖鎷ユ湁杩欎釜鍔ㄤ綔鐨勬帶鍒跺櫒銆 CAction
getEventHandlers() 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 CComponent
getId() 杩斿洖鍔ㄤ綔鐨処D銆 CAction
hasEvent() 纭畾涓涓簨浠舵槸鍚﹀畾涔夈 CComponent
hasEventHandler() 妫鏌ヤ簨浠舵槸鍚︽湁闄勫姞鐨勫鐞嗙▼搴忋 CComponent
hasProperty() 纭畾灞炴ф槸鍚﹁瀹氫箟銆 CComponent
raiseEvent() 鍙戣捣涓涓簨浠躲 CComponent
runWithParams() 杩愯甯︽湁璇锋眰鍙傛暟鐨勫璞° CAction

鍙椾繚鎶ゆ柟娉

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
runWithParamsInternal() 鎵ц涓涓甫鏈夊懡鍚嶅弬鏁扮殑瀵硅薄鐨勬柟娉曘 CAction

灞炴ц缁

controller 灞炴 鍙

鎷ユ湁杩欎釜鍔ㄤ綔鐨勬帶鍒跺櫒銆

id 灞炴 鍙
public string getId()

鍔ㄤ綔鐨処D銆

鏂规硶璇︾粏

__construct() 鏂规硶
public void __construct(CController $controller, string $id)
$controller CController 鎷ユ湁杩欎釜鍔ㄤ綔鐨勬帶鍒跺櫒銆
$id string 鍔ㄤ綔鐨処D銆
婧愮爜锛 framework/web/actions/CAction.php#40 (鏄剧ず)
public function __construct($controller,$id)
{
    
$this->_controller=$controller;
    
$this->_id=$id;
}

鏋勯犳柟娉曘

getController() 鏂规硶
public CController getController()
{return} CController 鎷ユ湁杩欎釜鍔ㄤ綔鐨勬帶鍒跺櫒銆
婧愮爜锛 framework/web/actions/CAction.php#49 (鏄剧ず)
public function getController()
{
    return 
$this->_controller;
}

getId() 鏂规硶
public string getId()
{return} string 鍔ㄤ綔鐨処D銆
婧愮爜锛 framework/web/actions/CAction.php#57 (鏄剧ず)
public function getId()
{
    return 
$this->_id;
}

runWithParams() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.7锛
public boolean runWithParams(array $params)
$params array 璇锋眰鍙傛暟锛堥敭鍚=>閿硷級
{return} boolean 鍛藉悕鍙傛暟鏄惁鏈夋晥鐨
婧愮爜锛 framework/web/actions/CAction.php#69 (鏄剧ず)
public function runWithParams($params)
{
    
$method=new ReflectionMethod($this'run');
    if(
$method->getNumberOfParameters()>0)
        return 
$this->runWithParamsInternal($this$method$params);
    else
        return 
$this->run();
}

杩愯甯︽湁璇锋眰鍙傛暟鐨勫璞° 杩欎釜鏂规硶閫氳繃CController::runAction()鍐呴儴璋冪敤銆

runWithParamsInternal() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.7锛
protected boolean runWithParamsInternal(mixed $object, ReflectionMethod $method, array $params)
$object mixed 瑕佹墽琛岀殑瀵硅薄鐨勬柟娉
$method ReflectionMethod 鏂规硶鏄犲皠
$params array 鍛藉悕鍙傛暟
{return} boolean 鍛藉悕鍙傛暟鏄惁鏈夋晥鐨
婧愮爜锛 framework/web/actions/CAction.php#87 (鏄剧ず)
protected function runWithParamsInternal($object$method$params)
{
    
$ps=array();
    foreach(
$method->getParameters() as $i=>$param)
    {
        
$name=$param->getName();
        if(isset(
$params[$name]))
        {
            if(
$param->isArray())
                
$ps[]=is_array($params[$name]) ? $params[$name] : array($params[$name]);
            else if(!
is_array($params[$name]))
                
$ps[]=$params[$name];
            else
                return 
false;
        }
        else if(
$param->isDefaultValueAvailable())
            
$ps[]=$param->getDefaultValue();
        else
            return 
false;
    }
    
$method->invokeArgs($object,$ps);
    return 
true;
}

鎵ц涓涓甫鏈夊懡鍚嶅弬鏁扮殑瀵硅薄鐨勬柟娉曘 杩欎釜鏂规硶鏄唴閮ㄤ娇鐢ㄣ

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.