Yii Framework v1.1.10 绫诲弬鑰

CFormModel

system.web
缁ф壙 class CFormModel » CModel » CComponent
瀹炵幇 ArrayAccess, Traversable, IteratorAggregate
瀛愮被 CCodeModel
婧愯嚜 1.0
鐗堟湰 $Id: CFormModel.php 3515 2011-12-28 12:29:24Z mdomba $
婧愮爜 framework/web/CFormModel.php
CFormModel浠h〃鏀堕泦HTML琛ㄥ崟杈撳叆鐨勬暟鎹ā鍨嬨

涓嶅悓浜CActiveRecord锛孋FormModel鏀堕泦鐨勬暟鎹彧瀛樺偍鍦ㄥ唴瀛樹腑锛 鑰屼笉鏄暟鎹簱涓

鏀堕泦鐢ㄦ埛杈撳叆锛屼綘鍙兘浼氭墿灞旵FormModel瀹氫箟鐨勫睘鎬т互鎺ュ彈鐢ㄦ埛鐨勮緭鍏ヤ俊鎭 浣犲彲鑳戒細鏍规嵁搴旂敤鐨勫睘鎬ц鐩 rules()鏉ュ0鏄 楠岃瘉瑙勫垯銆

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
attributes array Returns all attribute values. CModel
errors array Returns the errors for all attribute or a single attribute. CModel
iterator CMapIterator Returns an iterator for traversing the attributes in the model. CModel
safeAttributeNames array Returns the attribute names that are safe to be massively assigned. CModel
scenario string Returns the scenario that this model is used in. CModel
validatorList CList Returns all the validators declared in the model. CModel
validators array Returns the validators applicable to the current scenario. CModel

鍏叡鏂规硶

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
__call() 濡傛灉绫讳腑娌℃湁璋冪殑鏂规硶鍚嶏紝鍒欒皟鐢ㄨ繖涓柟娉曘 CComponent
__construct() 鏋勯犳柟娉曘 CFormModel
__get() 杩斿洖涓涓睘鎬у笺佷竴涓簨浠跺鐞嗙▼搴忓垪琛ㄦ垨涓涓涓哄悕绉般 CComponent
__isset() 妫鏌ヤ竴涓睘鎬ф槸鍚︿负null銆 CComponent
__set() 璁剧疆涓涓粍浠剁殑灞炴у笺 CComponent
__unset() 璁剧疆涓涓粍浠剁殑灞炴т负null銆 CComponent
addError() Adds a new error to the specified attribute. CModel
addErrors() Adds a list of errors. CModel
asa() 杩斿洖杩欎釜鍚嶅瓧鐨勮涓哄璞° CComponent
attachBehavior() 闄勫姞涓涓涓哄埌缁勪欢銆 CComponent
attachBehaviors() 闄勫姞涓涓涓哄垪琛ㄥ埌缁勪欢銆 CComponent
attachEventHandler() 涓轰簨浠堕檮鍔犱竴涓簨浠跺鐞嗙▼搴忋 CComponent
attributeLabels() Returns the attribute labels. CModel
attributeNames() 杩斿洖灞炴у悕鍒楄〃銆 CFormModel
behaviors() Returns a list of behaviors that this model should behave as. CModel
canGetProperty() 纭畾灞炴ф槸鍚﹀彲璇汇 CComponent
canSetProperty() 纭畾灞炴ф槸鍚﹀彲鍐欍 CComponent
clearErrors() Removes errors for all attributes or a single attribute. CModel
createValidators() Creates validator objects based on the specification in rules. CModel
detachBehavior() 浠庣粍浠朵腑鍒嗙涓涓涓恒 CComponent
detachBehaviors() 浠庣粍浠朵腑鍒嗙鎵鏈夎涓恒 CComponent
detachEventHandler() 鍒嗙涓涓瓨鍦ㄧ殑浜嬩欢澶勭悊绋嬪簭銆 CComponent
disableBehavior() 绂佺敤涓涓檮鍔犺涓恒 CComponent
disableBehaviors() 绂佺敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
enableBehavior() 鍚敤涓涓檮鍔犺涓恒 CComponent
enableBehaviors() 鍚敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
evaluateExpression() 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 CComponent
generateAttributeLabel() Generates a user friendly attribute label. CModel
getAttributeLabel() Returns the text label for the specified attribute. CModel
getAttributes() Returns all attribute values. CModel
getError() Returns the first error of the specified attribute. CModel
getErrors() Returns the errors for all attribute or a single attribute. CModel
getEventHandlers() 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 CComponent
getIterator() Returns an iterator for traversing the attributes in the model. CModel
getSafeAttributeNames() Returns the attribute names that are safe to be massively assigned. CModel
getScenario() Returns the scenario that this model is used in. CModel
getValidatorList() Returns all the validators declared in the model. CModel
getValidators() Returns the validators applicable to the current scenario. CModel
hasErrors() Returns a value indicating whether there is any validation error. CModel
hasEvent() 纭畾涓涓簨浠舵槸鍚﹀畾涔夈 CComponent
hasEventHandler() 妫鏌ヤ簨浠舵槸鍚︽湁闄勫姞鐨勫鐞嗙▼搴忋 CComponent
hasProperty() 纭畾灞炴ф槸鍚﹁瀹氫箟銆 CComponent
init() 鍒濆鍖栨ā鍨嬨 CFormModel
isAttributeRequired() Returns a value indicating whether the attribute is required. CModel
isAttributeSafe() Returns a value indicating whether the attribute is safe for massive assignments. CModel
offsetExists() Returns whether there is an element at the specified offset. CModel
offsetGet() Returns the element at the specified offset. CModel
offsetSet() Sets the element at the specified offset. CModel
offsetUnset() Unsets the element at the specified offset. CModel
onAfterConstruct() This event is raised after the model instance is created by new operator. CModel
onAfterValidate() This event is raised after the validation is performed. CModel
onBeforeValidate() This event is raised before the validation is performed. CModel
onUnsafeAttribute() This method is invoked when an unsafe attribute is being massively assigned. CModel
raiseEvent() 鍙戣捣涓涓簨浠躲 CComponent
rules() Returns the validation rules for attributes. CModel
setAttributes() Sets the attribute values in a massive way. CModel
setScenario() Sets the scenario for the model. CModel
unsetAttributes() Sets the attributes to be null. CModel
validate() Performs the validation. CModel

鍙椾繚鎶ゆ柟娉

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
afterConstruct() This method is invoked after a model instance is created by new operator. CModel
afterValidate() This method is invoked after validation ends. CModel
beforeValidate() This method is invoked before validation starts. CModel

浜嬩欢

闅愯棌缁ф壙浜嬩欢

浜嬩欢鎻忚堪瀹氫箟鍦
onAfterConstruct This event is raised after the model instance is created by new operator. CModel
onBeforeValidate This event is raised before the validation is performed. CModel
onAfterValidate This event is raised after the validation is performed. CModel
onUnsafeAttribute This method is invoked when an unsafe attribute is being massively assigned. CModel

鏂规硶璇︾粏

__construct() 鏂规硶
public void __construct(string $scenario='')
$scenario string 妯″瀷浣跨敤鐨勫満鏅悕绉般 See CModel::scenario濡備綍浣跨敤妯″瀷鍦烘櫙銆
婧愮爜锛 framework/web/CFormModel.php#37 (鏄剧ず)
public function __construct($scenario='')
{
    
$this->setScenario($scenario);
    
$this->init();
    
$this->attachBehaviors($this->behaviors());
    
$this->afterConstruct();
}

鏋勯犳柟娉曘

鍙傝

attributeNames() 鏂规硶
public array attributeNames()
{return} array 灞炴у悕鍒楄〃銆傞粯璁や负绫荤殑鎵鏈夊叕鍏卞睘鎬с
婧愮爜锛 framework/web/CFormModel.php#61 (鏄剧ず)
public function attributeNames()
{
    
$className=get_class($this);
    if(!isset(
self::$_names[$className]))
    {
        
$class=new ReflectionClass(get_class($this));
        
$names=array();
        foreach(
$class->getProperties() as $property)
        {
            
$name=$property->getName();
            if(
$property->isPublic() && !$property->isStatic())
                
$names[]=$name;
        }
        return 
self::$_names[$className]=$names;
    }
    else
        return 
self::$_names[$className];
}

杩斿洖灞炴у悕鍒楄〃銆 榛樿锛岃繖涓柟娉曡繑鍥炴墍鏈夌殑鍏叡灞炴с 鎮ㄥ彲浠ラ噸鍐欐鏂规硶鏉ユ洿鏀归粯璁ゃ

init() 鏂规硶
public void init()
婧愮爜锛 framework/web/CFormModel.php#51 (鏄剧ず)
public function init()
{
}

鍒濆鍖栨ā鍨嬨 鍦scenario璁剧疆鍚庤皟鐢ㄦ鏂规硶鏋勯犮 鎮ㄥ彲浠ラ噸鍐欐鏂规硶锛屼互鎻愪緵鎵闇瑕佺殑浠g爜鏉ュ垵濮嬪寲妯″瀷 锛堝锛氳缃垵濮嬪睘鎬у笺傦級

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