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鏄 楠岃瘉瑙勫垯銆
涓嶅悓浜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()
|
鍒濆鍖栨ā鍨嬨 鍦scenario璁剧疆鍚庤皟鐢ㄦ鏂规硶鏋勯犮 鎮ㄥ彲浠ラ噸鍐欐鏂规硶锛屼互鎻愪緵鎵闇瑕佺殑浠g爜鏉ュ垵濮嬪寲妯″瀷 锛堝锛氳缃垵濮嬪睘鎬у笺傦級