CFormModel
包 | system.web |
---|---|
继承 | class CFormModel » CModel » CComponent |
实现 | ArrayAccess, Traversable, IteratorAggregate |
可用自 | 1.0 |
版本 | $Id$ |
CFormModel represents a data model that collects HTML form inputs.
Unlike CActiveRecord, the data collected by CFormModel are stored in memory only, instead of database.
To collect user inputs, you may extend CFormModel and define the attributes whose values are to be collected from user inputs. You may override rules() to declare validation rules that should be applied to the attributes.
Unlike CActiveRecord, the data collected by CFormModel are stored in memory only, instead of database.
To collect user inputs, you may extend CFormModel and define the attributes whose values are to be collected from user inputs. You may override rules() to declare validation rules that should be applied to the attributes.
公共属性
属性 | 类型 | 描述 | 被定义在 |
---|---|---|---|
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 in. | CModel |
validators | array | list of validators created according to rules. | CFormModel |
公共方法
方法 | 描述 | 被定义在 |
---|---|---|
__call() | Calls the named method which is not a class method. | CComponent |
__construct() | Constructor. | CFormModel |
__get() | Returns a property value, an event handler list or a behavior based on its name. | CComponent |
__isset() | Checks if a property value is null. | CComponent |
__set() | Sets value of a component property. | CComponent |
__unset() | Sets a component property to be null. | CComponent |
addError() | Adds a new error to the specified attribute. | CModel |
addErrors() | Adds a list of errors. | CModel |
asa() | Returns the named behavior object. | CComponent |
attachBehavior() | Attaches a behavior to this component. | CComponent |
attachBehaviors() | Attaches a list of behaviors to the component. | CComponent |
attachEventHandler() | Attaches an event handler to an event. | CComponent |
attributeLabels() | Returns the attribute labels. | CModel |
attributeNames() | Returns the list of attribute names. | CFormModel |
behaviors() | Returns a list of behaviors that this model should behave as. | CModel |
canGetProperty() | Determines whether a property can be read. | CComponent |
canSetProperty() | Determines whether a property can be set. | CComponent |
clearErrors() | Removes errors for all attributes or a single attribute. | CModel |
createValidators() | CModel | |
detachBehavior() | Detaches a behavior from the component. | CComponent |
detachBehaviors() | Detaches all behaviors from the component. | CComponent |
detachEventHandler() | Detaches an existing event handler. | CComponent |
disableBehavior() | Disables an attached behavior. | CComponent |
disableBehaviors() | Disables all behaviors attached to this component. | CComponent |
enableBehavior() | Enables an attached behavior. | CComponent |
enableBehaviors() | Enables all behaviors attached to this component. | 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() | Returns the list of attached event handlers for an event. | 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 in. | CModel |
getValidators() | CFormModel | |
getValidatorsForAttribute() | Returns the validators that are applied to the specified attribute under the specified scenario. | CModel |
hasErrors() | Returns a value indicating whether there is any validation error. | CModel |
hasEvent() | Determines whether an event is defined. | CComponent |
hasEventHandler() | Checks whether the named event has attached handlers. | CComponent |
hasProperty() | Determines whether a property is defined. | CComponent |
init() | Initializes this model. | CFormModel |
isAttributeRequired() | Returns a value indicating whether the attribute is required. | 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 |
onAfterValidate() | This event is raised after the validation is performed. | CModel |
onBeforeValidate() | This event is raised before the validation is performed. | CModel |
raiseEvent() | Raises an event. | CComponent |
rules() | Returns the validation rules for attributes. | CModel |
safeAttributes() | Returns the name of attributes that are safe to be massively assigned. | CFormModel |
setAttributes() | Sets the attribute values in a massive way. | CModel |
setScenario() | CModel | |
validate() | Performs the validation. | CModel |
受保护的方法
方法 | 描述 | 被定义在 |
---|---|---|
afterValidate() | This method is invoked after validation ends. | CModel |
beforeValidate() | This method is invoked before validation starts. | CModel |
事件
事件 | 描述 | 被定义在 |
---|---|---|
onBeforeValidate | This event is raised before the validation is performed. | CModel |
onAfterValidate | This event is raised after the validation is performed. | CModel |
属性详情
validators
属性
只读
public array getValidators()
list of validators created according to rules.
方法详情
__construct()
方法
public void __construct(array $attributes=array (
), string $scenario='')
| ||
$attributes | array | initial attributes (name => value). The attributes are subject to filtering via setAttributes. |
$scenario | string | scenario name. See setAttributes for more details about this parameter. This parameter has been available since version 1.0.2. As of version 1.0.4, this parameter will be used to set the scenario property of the model. |
Constructor.
attributeNames()
方法
public array attributeNames()
| ||
{return} | array | list of attribute names. Defaults to all public properties of the class. |
Returns the list of attribute names. By default, this method returns all public properties of the class. You may override this method to change the default.
getValidators()
方法
public array getValidators()
| ||
{return} | array | list of validators created according to rules. |
init()
方法
(自版本 v1.0.8 可用)
public void init()
|
Initializes this model. This method is invoked in the constructor right after scenario is set. You may override this method to provide code that is needed to initialize the model (e.g. setting initial property values.)
safeAttributes()
方法
(自版本 v1.0.2 可用)
public array safeAttributes()
| ||
{return} | array | list of safe attribute names. |
Returns the name of attributes that are safe to be massively assigned. The default implementation simply returns attributeNames. This method may be overridden by child classes. See CModel::safeAttributes for more details about how to override this method.