CFormElement
包 | system.web.form |
---|---|
继承 | abstract class CFormElement » CComponent |
子类 | CForm, CFormButtonElement, CFormInputElement, CFormStringElement |
可用自 | 1.1 |
源码 | framework/web/form/CFormElement.php |
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 |
属性详情
list of attributes (name=>value) for the HTML element represented by this object.
the direct parent of this element. This could be either a CForm object or a CBaseController object (a controller or a widget).
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.
方法详情
public void __construct(mixed $config, mixed $parent)
| ||
$config | mixed | the configuration for this element. |
$parent | mixed | the direct parent of this element. |
public function __construct($config,$parent)
{
$this->configure($config);
$this->_parent=$parent;
}
Constructor.
参见
public mixed __get(string $name)
| ||
$name | string | the property or attribute name |
{return} | mixed | the property or attribute value |
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;
参见
public boolean __isset(string $name)
| ||
$name | string | the property or attribute name |
{return} | boolean |
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);
public void __set(string $name, mixed $value)
| ||
$name | string | the property or attribute name |
$value | mixed | the property or attribute value |
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;
参见
public string __toString()
| ||
{return} | string | the string representation of this object. |
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.
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. |
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.
protected boolean evaluateVisible()
| ||
{return} | boolean | whether this element is visible. Defaults to true. |
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.
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). |
public function getParent()
{
return $this->_parent;
}
public boolean getVisible()
| ||
{return} | boolean | whether this element is visible and should be rendered. |
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.
abstract public string render()
| ||
{return} | string | the rendering result |
Renders this element.
public void setVisible(boolean $value)
| ||
$value | boolean | whether this element is visible and should be rendered. |
public function setVisible($value)
{
$this->_visible=$value;
}