system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.cubrid system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.gii system.i18n system.i18n.gettext system.logging system.test system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.form system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers zii.behaviors zii.widgets zii.widgets.grid zii.widgets.jui

CFormElementCollection

system.web.form
继承 class CFormElementCollection » CMap » CComponent
实现 Countable, ArrayAccess, Traversable, IteratorAggregate
可用自 1.1
源码 framework/web/form/CFormElementCollection.php
CFormElementCollection implements the collection for storing form elements.

Because CFormElementCollection extends from CMap, it can be used like an associative array. For example,
$element=$collection['username'];
$collection['username']=array('type'=>'text', 'maxlength'=>128);
$collection['password']=new CFormInputElement(array('type'=>'password'),$form);
$collection[]='some string';


CFormElementCollection can store three types of value: a configuration array, a CFormElement object, or a string, as shown in the above example. Internally, these values will be converted to CFormElement objects.

公共属性

隐藏继承的属性

属性类型描述被定义在
count integer Returns the number of items in the map. CMap
iterator CMapIterator Returns an iterator for traversing the items in the list. CMap
keys array the key list CMap
readOnly boolean whether this map is read-only or not. CMap

公共方法

隐藏继承的方法

方法描述被定义在
__call() Calls the named method which is not a class method. CComponent
__construct() Constructor. CFormElementCollection
__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
add() Adds an item to the collection. CFormElementCollection
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
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
clear() Removes all items in the map. CMap
contains() CMap
copyFrom() Copies iterable data into the map. CMap
count() Returns the number of items in the map. CMap
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
evaluateExpression() Evaluates a PHP expression or callback under the context of this component. CComponent
getCount() Returns the number of items in the map. CMap
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getIterator() Returns an iterator for traversing the items in the list. CMap
getKeys() Returns the key list CMap
getReadOnly() Returns whether this map is read-only or not. Defaults to false. CMap
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
itemAt() Returns the item with the specified key. CMap
mergeArray() Merges two or more arrays into one recursively. CMap
mergeWith() Merges iterable data into the map. CMap
offsetExists() Returns whether there is an element at the specified offset. CMap
offsetGet() Returns the element at the specified offset. CMap
offsetSet() Sets the element at the specified offset. CMap
offsetUnset() Unsets the element at the specified offset. CMap
raiseEvent() Raises an event. CComponent
remove() Removes the specified element by key. CFormElementCollection
toArray() CMap

受保护的方法

隐藏继承的方法

方法描述被定义在
setReadOnly() Sets whether this list is read-only or not CMap

方法详情

__construct() 方法
public void __construct(CForm $form, boolean $forButtons=false)
$form CForm the form object that owns this collection
$forButtons boolean whether this collection is used to store buttons.
源码: framework/web/form/CFormElementCollection.php#41 (显示)
public function __construct($form,$forButtons=false)
{
    
parent::__construct();
    
$this->_form=$form;
    
$this->_forButtons=$forButtons;
}

Constructor.

add() 方法
public void add(mixed $key, mixed $value)
$key mixed key
$value mixed value
源码: framework/web/form/CFormElementCollection.php#57 (显示)
public function add($key,$value)
{
    if(
is_array($value))
    {
        if(
is_string($key))
            
$value['name']=$key;

        if(
$this->_forButtons)
        {
            
$class=$this->_form->buttonElementClass;
            
$element=new $class($value,$this->_form);
        }
        else
        {
            if(!isset(
$value['type']))
                
$value['type']='text';
            if(
$value['type']==='string')
            {
                unset(
$value['type'],$value['name']);
                
$element=new CFormStringElement($value,$this->_form);
            }
            elseif(!
strcasecmp(substr($value['type'],-4),'form'))    // a form
            
{
                
$class=$value['type']==='form' get_class($this->_form) : Yii::import($value['type']);
                
$element=new $class($value,null,$this->_form);
            }
            else
            {
                
$class=$this->_form->inputElementClass;
                
$element=new $class($value,$this->_form);
            }
        }
    }
    elseif(
$value instanceof CFormElement)
    {
        if(
property_exists($value,'name') && is_string($key))
            
$value->name=$key;
        
$element=$value;
    }
    else
        
$element=new CFormStringElement(array('content'=>$value),$this->_form);
    
parent::add($key,$element);
    
$this->_form->addedElement($key,$element,$this->_forButtons);
}

Adds an item to the collection. This method overrides the parent implementation to ensure only configuration arrays, strings, or CFormElement objects can be stored in this collection.

remove() 方法
public void remove(string $key)
$key string the name of the element to be removed from the collection
源码: framework/web/form/CFormElementCollection.php#107 (显示)
public function remove($key)
{
    if((
$item=parent::remove($key))!==null)
        
$this->_form->removedElement($key,$item,$this->_forButtons);
}

Removes the specified element by key.