0 follower

CFormElement

Package system.web.form
Inheritance abstract class CFormElement » CComponent
Subclasses CForm, CFormButtonElement, CFormInputElement, CFormStringElement
Since 1.1
Source Code 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.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
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

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__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

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
evaluateVisible() Evaluates the visibility of this element. CFormElement

Property Details

attributes property
public array $attributes;

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

parent property read-only
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 property
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.

Method Details

__construct() method
public void __construct(mixed $config, mixed $parent)
$config mixed the configuration for this element.
$parent mixed the direct parent of this element.
Source Code: framework/web/form/CFormElement.php#46 (show)
public function __construct($config,$parent)
{
    
$this->configure($config);
    
$this->_parent=$parent;
}

Constructor.

See Also

__get() method
public mixed __get(string $name)
$name string the property or attribute name
{return} mixed the property or attribute value
Source Code: framework/web/form/CFormElement.php#77 (show)
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;

See Also

__isset() method
public boolean __isset(string $name)
$name string the property or attribute name
{return} boolean
Source Code: framework/web/form/CFormElement.php#99 (show)
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() method
public void __set(string $name, mixed $value)
$name string the property or attribute name
$value mixed the property or attribute value
Source Code: framework/web/form/CFormElement.php#122 (show)
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;

See Also

__toString() method
public string __toString()
{return} string the string representation of this object.
Source Code: framework/web/form/CFormElement.php#59 (show)
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() method
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.
Source Code: framework/web/form/CFormElement.php#138 (show)
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() method
protected boolean evaluateVisible()
{return} boolean whether this element is visible. Defaults to true.
Source Code: framework/web/form/CFormElement.php#184 (show)
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() method
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).
Source Code: framework/web/form/CFormElement.php#173 (show)
public function getParent()
{
    return 
$this->_parent;
}

getVisible() method
public boolean getVisible()
{return} boolean whether this element is visible and should be rendered.
Source Code: framework/web/form/CFormElement.php#154 (show)
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() method
abstract public string render()
{return} string the rendering result
Source Code: framework/web/form/CFormElement.php#38 (show)
abstract function render();

Renders this element.

setVisible() method
public void setVisible(boolean $value)
$value boolean whether this element is visible and should be rendered.
Source Code: framework/web/form/CFormElement.php#164 (show)
public function setVisible($value)
{
    
$this->_visible=$value;
}