CFormElement

优质
小牛编辑
126浏览
2023-12-01
所有包 | 属性 | 方法
system.web.form
继承abstract class CFormElement » CComponent
子类CForm, CFormButtonElement, CFormInputElement, CFormStringElement
源自1.1
版本$Id: CFormElement.php 3426 2011-10-25 00:01:09Z alexander.makarow $
源码framework/web/form/CFormElement.php
CFormElement 是各种表单元素的基类。

CFormElement 实现了获取和设置任意的属性的方法。

公共属性

隐藏继承属性

属性类型描述定义在
attributesarray通过这个对象来表现HTML元素的属性列表(name=>value)。CFormElement
parentmixed这个元素的真系父类。它可能是CForm对象,也可能是CBaseController对象。 (控制器或挂件)。CFormElement
visibleboolean返回值说明这个元素是否可见并需要渲染。CFormElement

公共方法

隐藏继承方法

方法描述定义在
__call()如果类中没有调的方法名,则调用这个方法。CComponent
__construct()构造器。CFormElement
__get()返回属性值。CFormElement
__isset()检查一个属性是否为null。CComponent
__set()设置属性值。CFormElement
__toString()将对象转换为字符串。CFormElement
__unset()设置一个组件的属性为null。CComponent
asa()返回这个名字的行为对象。CComponent
attachBehavior()附加一个行为到组件。CComponent
attachBehaviors()附加一个行为列表到组件。CComponent
attachEventHandler()为事件附加一个事件处理程序。CComponent
canGetProperty()确定属性是否可读。CComponent
canSetProperty()确定属性是否可写。CComponent
configure()根据初始化的值来配置这个对象。CFormElement
detachBehavior()从组件中分离一个行为。CComponent
detachBehaviors()从组件中分离所有行为。CComponent
detachEventHandler()分离一个存在的事件处理程序。CComponent
disableBehavior()禁用一个附加行为。CComponent
disableBehaviors()禁用组件附加的所有行为。CComponent
enableBehavior()启用一个附加行为。CComponent
enableBehaviors()启用组件附加的所有行为。CComponent
evaluateExpression()计算一个PHP表达式,或根据组件上下文执行回调。CComponent
getEventHandlers()返回一个事件的附加处理程序列表。CComponent
getParent()返回这个元素的真系父类。它可能是CForm对象,也可能是CBaseController对象。 (控制器或挂件)。CFormElement
getVisible()返回值说明这个元素是否可见并需要渲染。CFormElement
hasEvent()确定一个事件是否定义。CComponent
hasEventHandler()检查事件是否有附加的处理程序。CComponent
hasProperty()确定属性是否被定义。CComponent
raiseEvent()发起一个事件。CComponent
render()渲染这个元素。CFormElement
setVisible()设置这个元素是否可见并需要渲染。CFormElement

受保护方法

隐藏继承方法

方法描述定义在
evaluateVisible()评估这个元素是否可见。CFormElement

属性详细

attributes 属性 public array $attributes;

通过这个对象来表现HTML元素的属性列表(name=>value)。

parent 属性 只读 public mixed getParent()

这个元素的真系父类。它可能是CForm对象,也可能是CBaseController对象。 (控制器或挂件)。

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

返回值说明这个元素是否可见并需要渲染。 这个方法将调用evaluateVisible来确定这个元素是否可见。

方法详细

__construct() 方法
public void __construct(mixed $config, mixed $parent)
$configmixed这个元素的配置。
$parentmixed这个元素的真系父类。
源码: framework/web/form/CFormElement.php#47 (显示) publicfunction__construct($config,$parent)
{
$this->configure($config);
$this->_parent=$parent;
}

构造器。

参见

  • configure
__get() 方法
public mixed __get(string $name)
$namestring属性名
{return}mixed属性值
源码: framework/web/form/CFormElement.php#78 (显示) publicfunction__get($name)
{
$getter='get'.$name;
if(method_exists($this,$getter))
return$this->$getter();
elseif(isset($this->attributes[$name]))
return$this->attributes[$name];
else
thrownewCException(Yii::t('yii','Property"{class}.{property}"isnotdefined.',
array('{class}'=>get_class($this),'{property}'=>$name)));
}

返回属性值。 不要调用这个方法。这是一个被我们覆盖了的PHP的魔术方法, 它允许如下语法来读取属性值:

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

参见

  • __set
__set() 方法
public void __set(string $name, mixed $value)
$namestring属性名
$valuemixed属性值
源码: framework/web/form/CFormElement.php#102 (显示) publicfunction__set($name,$value)
{
$setter='set'.$name;
if(method_exists($this,$setter))
$this->$setter($value);
else
$this->attributes[$name]=$value;
}

设置属性值。 不要调用这个方法。这是一个被我们覆盖的PHP的魔术方法, 允许用如下语法设置一个属性的值。

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

参见

  • __get
__toString() 方法
public string __toString()
{return}string代表这个实体的字符串。
源码: framework/web/form/CFormElement.php#60 (显示) publicfunction__toString()
{
return$this->render();
}

将对象转换为字符串。 这是一个PHP的魔术方法。 默认实现是调用render 返回渲染结果。

configure() 方法
public void configure(mixed $config)
$configmixed这个对象的配置。 它可以是表示属性名和它们的初始化值的数组。 它也可以是能够返回一个配置数组的文件名It 或PHP脚本。
源码: framework/web/form/CFormElement.php#118 (显示) publicfunctionconfigure($config)
{
if(is_string($config))
$config=require(Yii::getPathOfAlias($config).'.php');
if(is_array($config))
{
foreach($configas$name=>$value)
$this->$name=$value;
}
}

根据初始化的值来配置这个对象。

evaluateVisible() 方法
protected boolean evaluateVisible()
{return}boolean这个元素是否可见。默认为true。
源码: framework/web/form/CFormElement.php#164 (显示) protectedfunctionevaluateVisible()
{
returntrue;
}

评估这个元素是否可见。 子类应该覆盖这个方法来实现真实的算法 来确定元素的可见性。

getParent() 方法
public mixed getParent()
{return}mixed这个元素的真系父类。它可能是CForm对象,也可能是CBaseController对象。 (控制器或挂件)。
源码: framework/web/form/CFormElement.php#153 (显示) publicfunctiongetParent()
{
return$this->_parent;
}
getVisible() 方法
public boolean getVisible()
{return}boolean这个元素是否可见并需要渲染。
源码: framework/web/form/CFormElement.php#134 (显示) publicfunctiongetVisible()
{
if($this->_visible===null)
$this->_visible=$this->evaluateVisible();
return$this->_visible;
}

返回值说明这个元素是否可见并需要渲染。 这个方法将调用evaluateVisible来确定这个元素是否可见。

render() 方法
abstract public string render()
{return}string渲染结果
源码: framework/web/form/CFormElement.php#39 (显示) abstractfunctionrender();

渲染这个元素。

setVisible() 方法
public void setVisible(boolean $value)
$valueboolean这个元素是否可见并需要渲染。
源码: framework/web/form/CFormElement.php#144 (显示) publicfunctionsetVisible($value)
{
$this->_visible=$value;
}