CFormButtonElement

优质
小牛编辑
122浏览
2023-12-01
所有包 | 属性 | 方法
system.web.form
继承class CFormButtonElement » CFormElement » CComponent
源自1.1
版本$Id: CFormButtonElement.php 3426 2011-10-25 00:01:09Z alexander.makarow $
源码framework/web/form/CFormButtonElement.php
CFormButtonElement 代表一个表单按钮元素。

CFormButtonElement 能代表如下基于type属性按钮的类型:
  • htmlButton: 一个由CHtml::htmlButton生成的正常的按钮
  • htmlReset 一个由CHtml::htmlButton生成的重置按钮
  • htmlSubmit: 一个由CHtml::htmlButton生成的提交按钮
  • submit: 一个由CHtml::submitButton生成的提交按钮
  • button: 一个由CHtml::button生成的正常的按钮
  • image: 一个由CHtml::imageButton生成的图片按钮
  • reset: 一个由CHtml::resetButton生成的重置按钮
  • link: 一个由CHtml::linkButton生成的链接按钮
type属性可以是一个类名或者一个类的路径别名。 既然这样,按钮可以由一个特定的类的挂件来生成。 注意,挂件必须有一个属性叫"name"。

因为CFormElement是CFormButtonElement的一个祖先类, 一个值指派给一个不存在的属性将被存储在attributes中, 然后作为一个HTML属性传递给CHtml方法来生成按钮或初始化挂件属性。

公共属性

隐藏继承属性

属性类型描述定义在
attributesarray通过这个对象来表现HTML元素的属性列表(name=>value)。CFormElement
coreTypes核心按钮类型(别名=>CHtml方法名)CFormButtonElement
labelstring按钮的标签.CFormButtonElement
namestring按钮的名称CFormButtonElement
onstring返回值表明这个按钮在哪些场景中是可见的。CFormButtonElement
parentmixed这个元素的真系父类。它可能是CForm对象,也可能是CBaseController对象。 (控制器或挂件)。CFormElement
typestring按钮的类型。它可以是一个类名,可以是一个类名的路径别名, 也可以是一个按钮类型别名(submit, button, image, reset, link, htmlButton, htmlSubmit, htmlReset).CFormButtonElement
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
getOn()返回值表明这个按钮在哪些场景中是可见的。CFormButtonElement
getParent()返回这个元素的真系父类。它可能是CForm对象,也可能是CBaseController对象。 (控制器或挂件)。CFormElement
getVisible()返回值说明这个元素是否可见并需要渲染。CFormElement
hasEvent()确定一个事件是否定义。CComponent
hasEventHandler()检查事件是否有附加的处理程序。CComponent
hasProperty()确定属性是否被定义。CComponent
raiseEvent()发起一个事件。CComponent
render()返回这个按钮。CFormButtonElement
setOn()设置逗号分隔的场景名。CFormButtonElement
setVisible()设置这个元素是否可见并需要渲染。CFormElement

受保护方法

隐藏继承方法

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

属性详细

coreTypes 属性 public static 核心按钮类型(别名=>CHtml方法名) $coreTypes; label 属性 public string $label;

按钮的标签. 当按钮是一个挂件生成时,这个属性被忽略。

name 属性 public string $name;

按钮的名称

on 属性 public string getOn()
public void setOn(string $value)

返回值表明这个按钮在哪些场景中是可见的。 如果这个值为空,意味着按钮在所有的场景中可见。 否则,只有当在场景中的模型名在这个值中能找到时, 按钮是可见的。 查看CModel::scenario来了解更多关于模型场景的信息。

type 属性 public string $type;

按钮的类型。它可以是一个类名,可以是一个类名的路径别名, 也可以是一个按钮类型别名(submit, button, image, reset, link, htmlButton, htmlSubmit, htmlReset).

方法详细

evaluateVisible() 方法
protected boolean evaluateVisible()
{return}boolean元素是否可见。
源码: framework/web/form/CFormButtonElement.php#135 (显示) protectedfunctionevaluateVisible()
{
returnempty($this->_on)||in_array($this->getParent()->getModel()->getScenario(),$this->_on);
}

评估这个元素是否可见。 这个方法将检查on属性来确定 如果模型在场景中那么应该字符串显示。

getOn() 方法
public string getOn()
{return}string逗号分隔的场景名。默认为null。
源码: framework/web/form/CFormButtonElement.php#80 (显示) publicfunctiongetOn()
{
return$this->_on;
}

返回值表明这个按钮在哪些场景中是可见的。 如果这个值为空,意味着按钮在所有的场景中可见。 否则,只有当在场景中的模型名在这个值中能找到时, 按钮是可见的。 查看CModel::scenario来了解更多关于模型场景的信息。

render() 方法
public string render()
{return}string渲染结果
源码: framework/web/form/CFormButtonElement.php#97 (显示) publicfunctionrender()
{
$attributes=$this->attributes;
if(isset(self::$coreTypes[$this->type]))
{
$method=self::$coreTypes[$this->type];
if($method==='linkButton')
{
if(!isset($attributes['params'][$this->name]))
$attributes['params'][$this->name]=1;
}
elseif($method==='htmlButton')
{
$attributes['type']=$this->type==='htmlSubmit'?'submit':($this->type==='htmlReset'?'reset':'button');
$attributes['name']=$this->name;
}
else
$attributes['name']=$this->name;
if($method==='imageButton')
returnCHtml::imageButton(isset($attributes['src'])?$attributes['src']:'',$attributes);
else
returnCHtml::$method($this->label,$attributes);
}
else
{
$attributes['name']=$this->name;
ob_start();
$this->getParent()->getOwner()->widget($this->type,$attributes);
returnob_get_clean();
}
}

返回这个按钮。

setOn() 方法
public void setOn(string $value)
$valuestring逗号分隔的场景名。
源码: framework/web/form/CFormButtonElement.php#88 (显示) publicfunctionsetOn($value)
{
$this->_on=preg_split('/[s,]+/',$value,-1,PREG_SPLIT_NO_EMPTY);
}