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

CFormElement

system.web.form
继承 abstract class CFormElement » CComponent
子类 CForm, CFormButtonElement, CFormInputElement, CFormStringElement
可用自 1.1
源码 framework/web/form/CFormElement.php
CFormElement is the base class for presenting all kinds of form element.

CFormElement implements the way to get and set arbitrary attributes.

公共属性

隐藏继承的属性

属性类型描述被定义在
attributes array list of attributes (name=>value) for the HTML element represented by this object. CFormElement
parent mixed the direct parent of this element. CFormElement
visible boolean Returns a value indicating whether this element is visible and should be rendered. CFormElement

公共方法

隐藏继承的方法

方法描述被定义在
__call() Calls the named method which is not a class method. CComponent
__construct() Constructor. CFormElement
__get() Returns a property value or an attribute value. CFormElement
__isset() Checks a property value or an attribute value on existence or not null CFormElement
__set() Sets value of a property or attribute. CFormElement
__toString() Converts the object to a string. CFormElement
__unset() Sets a component property to be null. CComponent
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
configure() Configures this object with property initial values. CFormElement
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
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getParent() Returns the direct parent of this element. This could be either a CForm object or a CBaseController object (a controller or a widget). CFormElement
getVisible() Returns a value indicating whether this element is visible and should be rendered. CFormElement
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
raiseEvent() Raises an event. CComponent
render() Renders this element. CFormElement
setVisible() Sets whether this element is visible and should be rendered. CFormElement

受保护的方法

隐藏继承的方法

方法描述被定义在
evaluateVisible() Evaluates the visibility of this element. CFormElement

属性详情

attributes 属性
public array $attributes;

list of attributes (name=>value) for the HTML element represented by this object.

parent 属性 只读
public mixed getParent()

the direct parent of this element. This could be either a CForm object or a CBaseController object (a controller or a widget).

visible 属性
public boolean getVisible()
public void setVisible(boolean $value)

Returns a value indicating whether this element is visible and should be rendered. This method will call evaluateVisible to determine the visibility of this element.

方法详情

__construct() 方法
public void __construct(mixed $config, mixed $parent)
$config mixed the configuration for this element.
$parent mixed the direct parent of this element.
源码: framework/web/form/CFormElement.php#46 (显示)
public function __construct($config,$parent)
{
    
$this->configure($config);
    
$this->_parent=$parent;
}

Constructor.

参见

__get() 方法
public mixed __get(string $name)
$name string the property or attribute name
{return} mixed the property or attribute value
源码: framework/web/form/CFormElement.php#77 (显示)
public function __get($name)
{
    
$getter='get'.$name;
    if(
method_exists($this,$getter))
        return 
$this->$getter();
    elseif(isset(
$this->attributes[$name]))
        return 
$this->attributes[$name];
    else
        throw new 
CException(Yii::t('yii','Property "{class}.{property}" is not defined.',
            array(
'{class}'=>get_class($this), '{property}'=>$name)));
}

Returns a property value or an attribute value. Do not call this method. This is a PHP magic method that we override to allow using the following syntax to read a property or attribute:

$value=$element->propertyName;
$value=$element->attributeName;

参见

__isset() 方法
public boolean __isset(string $name)
$name string the property or attribute name
{return} boolean
源码: framework/web/form/CFormElement.php#99 (显示)
public function __isset($name)
{
    
$getter='get'.$name;
    if(
method_exists($this,$getter))
        return 
$this->$getter()!==null;
    elseif(isset(
$this->attributes[$name]))
        return isset(
$this->attributes[$name]);
    else
        return 
false;
}

Checks a property value or an attribute value on existence or not null Do not call this method. This is a PHP magic method that we override to allow using the following syntax to read a property or attribute:

isset($element->propertyName);

__set() 方法
public void __set(string $name, mixed $value)
$name string the property or attribute name
$value mixed the property or attribute value
源码: framework/web/form/CFormElement.php#122 (显示)
public function __set($name,$value)
{
    
$setter='set'.$name;
    if(
method_exists($this,$setter))
        
$this->$setter($value);
    else
        
$this->attributes[$name]=$value;
}

Sets value of a property or attribute. Do not call this method. This is a PHP magic method that we override to allow using the following syntax to set a property or attribute.

$this->propertyName=$value;
$this->attributeName=$value;

参见

__toString() 方法
public string __toString()
{return} string the string representation of this object.
源码: framework/web/form/CFormElement.php#59 (显示)
public function __toString()
{
    return 
$this->render();
}

Converts the object to a string. This is a PHP magic method. The default implementation simply calls render and return the rendering result.

configure() 方法
public void configure(mixed $config)
$config mixed the configuration for this object. This can be an array representing the property names and their initial values. It can also be a string representing the file name of the PHP script that returns a configuration array.
源码: framework/web/form/CFormElement.php#138 (显示)
public function configure($config)
{
    if(
is_string($config))
        
$config=require(Yii::getPathOfAlias($config).'.php');
    if(
is_array($config))
    {
        foreach(
$config as $name=>$value)
            
$this->$name=$value;
    }
}

Configures this object with property initial values.

evaluateVisible() 方法
protected boolean evaluateVisible()
{return} boolean whether this element is visible. Defaults to true.
源码: framework/web/form/CFormElement.php#184 (显示)
protected function evaluateVisible()
{
    return 
true;
}

Evaluates the visibility of this element. Child classes should override this method to implement the actual algorithm for determining the visibility.

getParent() 方法
public mixed getParent()
{return} mixed the direct parent of this element. This could be either a CForm object or a CBaseController object (a controller or a widget).
源码: framework/web/form/CFormElement.php#173 (显示)
public function getParent()
{
    return 
$this->_parent;
}

getVisible() 方法
public boolean getVisible()
{return} boolean whether this element is visible and should be rendered.
源码: framework/web/form/CFormElement.php#154 (显示)
public function getVisible()
{
    if(
$this->_visible===null)
        
$this->_visible=$this->evaluateVisible();
    return 
$this->_visible;
}

Returns a value indicating whether this element is visible and should be rendered. This method will call evaluateVisible to determine the visibility of this element.

render() 方法
abstract public string render()
{return} string the rendering result
源码: framework/web/form/CFormElement.php#38 (显示)
abstract function render();

Renders this element.

setVisible() 方法
public void setVisible(boolean $value)
$value boolean whether this element is visible and should be rendered.
源码: framework/web/form/CFormElement.php#164 (显示)
public function setVisible($value)
{
    
$this->_visible=$value;
}