CFormInputElement

CDbHttpSession

Yii Framework v1.1.10 类参考

CFormInputElement

system.web.form
继承 class CFormInputElement » CFormElement » CComponent
源自 1.1
版本 $Id: CFormInputElement.php 3426 2011-10-25 00:01:09Z alexander.makarow $
源码 framework/web/form/CFormInputElement.php
CFormInputElement 代表表单输入元素。

CFormInputElement 可以代表以下基于type属性的表单输入类型: type属性可以是一个类名,也可以是一个类的路径别名。在这种情况下, 输入框是由指定的类的挂件生成的。 注意,挂件中必须有一个叫做“model”的属性指向一个模型对象, 和一个叫做“attribute”的属性指向模型属性。 因为CFormElement是CFormInputElement的一个祖先类, 给一个不存在的属性赋值将会存储在attributes,然后作为HTML属性传递给CHtml方法 生成输入框或初始化挂件的属性值。

公共属性

隐藏继承属性

属性类型描述定义在
attributes array 通过这个对象来表现HTML元素的属性列表(name=>value)。 CFormElement
coreTypes array 核心的输入类型(别名=>CHtml方法名) CFormInputElement
enableAjaxValidation boolean 是否允许这个输入元素基于AJAX验证。 注意,要使用基于AJAX验证,CForm::activeForm必须配置成'enableAjaxValidation'=>true。 这个属性允许打开或关闭单个输入栏的基于AJAX验证。 默认为true。 CFormInputElement
enableClientValidation boolean 是否允许这个输入元素客户端验证。 注意,要使用客户端验证,CForm::activeForm必须配置成'enableClientValidation'=>true. CFormInputElement
errorOptions array 渲染错误部分的选项。 这个属性会传递给CActiveForm::error方法,当作$htmlOptions来调用。 CFormInputElement
hint string 输入框的提示文本 CFormInputElement
items array 当元素是多选列表,下拉列表,复选框列表或单选按钮列表时的选项。 生成这些属性值的详细情况请查看CHtml::listData CFormInputElement
label string 输入元素的标签,如果没有手动设置这个标签, 该方法将调用CModel::getAttributeLabel来确定标签。 CFormInputElement
layout string 用于渲染标签,输入元素,提示和错误的布局。 它们对应到这些点位符:"{label}", "{input}", "{hint}" and "{error}". CFormInputElement
name string 输入框的名称 CFormInputElement
parent mixed 这个元素的真系父类。它可能是CForm对象,也可能是CBaseController对象。 (控制器或挂件)。 CFormElement
required boolean 得到的值表明这个输入元素是否为必须的。 CFormInputElement
type string 输入框的类型。可以是一个挂件的类名,可以是一个挂件类名的路径别名, 还可以是一个输入类型的别名(text, hidden, password, textarea, file, radio, checkbox, listbox, dropdownlist, checkboxlist, or radiolist). CFormInputElement
visible boolean 返回值说明这个元素是否可见并需要渲染。 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
getLabel() 返回输入元素的标签,如果没有手动设置这个标签, 该方法将调用CModel::getAttributeLabel来确定标签。 CFormInputElement
getParent() 返回这个元素的真系父类。它可能是CForm对象,也可能是CBaseController对象。 (控制器或挂件)。 CFormElement
getRequired() 得到的值表明这个输入元素是否为必须的。 CFormInputElement
getVisible() 返回值说明这个元素是否可见并需要渲染。 CFormElement
hasEvent() 确定一个事件是否定义。 CComponent
hasEventHandler() 检查事件是否有附加的处理程序。 CComponent
hasProperty() 确定属性是否被定义。 CComponent
raiseEvent() 发起一个事件。 CComponent
render() 渲染这个输入元素的所有内容。 CFormInputElement
renderError() 渲染这个输入元素的错误显示。 CFormInputElement
renderHint() 渲染这个输入元素的提示文本。 CFormInputElement
renderInput() 渲染输入元素。 CFormInputElement
renderLabel() 渲染这个输入元素的标签。Renders the label for this input. CFormInputElement
setLabel() 设置输入元素的标签 CFormInputElement
setRequired() 设置这个输入元素是否为必须的。 CFormInputElement
setVisible() 设置这个元素是否可见并需要渲染。 CFormElement

受保护方法

隐藏继承方法

方法描述定义在
evaluateVisible() 评估元素的可见性。Evaluates the visibility of this element. CFormInputElement

属性详细

coreTypes 属性
public static array $coreTypes;

核心的输入类型(别名=>CHtml方法名)

enableAjaxValidation 属性 (可用自 v1.1.7)
public boolean $enableAjaxValidation;

是否允许这个输入元素基于AJAX验证。 注意,要使用基于AJAX验证,CForm::activeForm必须配置成'enableAjaxValidation'=>true。 这个属性允许打开或关闭单个输入栏的基于AJAX验证。 默认为true。

enableClientValidation 属性 (可用自 v1.1.7)
public boolean $enableClientValidation;

是否允许这个输入元素客户端验证。 注意,要使用客户端验证,CForm::activeForm必须配置成'enableClientValidation'=>true. 这个属性允许打开或关闭单个输入栏的客户端验证。 默认为true。

errorOptions 属性 (可用自 v1.1.1)
public array $errorOptions;

渲染错误部分的选项。 这个属性会传递给CActiveForm::error方法,当作$htmlOptions来调用。

hint 属性
public string $hint;

输入框的提示文本

items 属性
public array $items;

当元素是多选列表,下拉列表,复选框列表或单选按钮列表时的选项。 生成这些属性值的详细情况请查看CHtml::listData

label 属性
public string getLabel()
public void setLabel(string $value)

输入元素的标签,如果没有手动设置这个标签, 该方法将调用CModel::getAttributeLabel来确定标签。

layout 属性
public string $layout;

用于渲染标签,输入元素,提示和错误的布局。 它们对应到这些点位符:"{label}", "{input}", "{hint}" and "{error}".

name 属性
public string $name;

输入框的名称

required 属性
public boolean getRequired()
public void setRequired(boolean $value)

得到的值表明这个输入元素是否为必须的。 如果这个属性没有明确设置, 它将会调用CModel::isAttributeRequired获得相关的模型和属性来决定。

type 属性
public string $type;

输入框的类型。可以是一个挂件的类名,可以是一个挂件类名的路径别名, 还可以是一个输入类型的别名(text, hidden, password, textarea, file, radio, checkbox, listbox, dropdownlist, checkboxlist, or radiolist). 如果是一个挂件类,那它必须是继承于CInputWidget或(@link CJuiInputWidget).

方法详细

evaluateVisible() 方法
protected boolean evaluateVisible()
{return} boolean 这个元素是否可见
源码: framework/web/form/CFormInputElement.php#250 (显示)
protected function evaluateVisible()
{
    return 
$this->getParent()->getModel()->isAttributeSafe($this->name);
}

评估元素的可见性。Evaluates the visibility of this element. 这个方法将检查这个输入元素的属性 在当前的场景中是否是安全的。

getLabel() 方法
public string getLabel()
{return} string 输入元素的标签,如果没有手动设置这个标签, 该方法将调用CModel::getAttributeLabel来确定标签。
源码: framework/web/form/CFormInputElement.php#141 (显示)
public function getLabel()
{
    if(
$this->_label!==null)
        return 
$this->_label;
    else
        return 
$this->getParent()->getModel()->getAttributeLabel($this->name);
}

getRequired() 方法
public boolean getRequired()
{return} boolean 这个输入元素是否为必须的。
源码: framework/web/form/CFormInputElement.php#121 (显示)
public function getRequired()
{
    if(
$this->_required!==null)
        return 
$this->_required;
    else
        return 
$this->getParent()->getModel()->isAttributeRequired($this->name);
}

得到的值表明这个输入元素是否为必须的。 如果这个属性没有明确设置, 它将会调用CModel::isAttributeRequired获得相关的模型和属性来决定。

render() 方法
public string render()
{return} string 输入元素完整的渲染结果,包括标签,输入框,提示和错误。
源码: framework/web/form/CFormInputElement.php#164 (显示)
public function render()
{
    if(
$this->type==='hidden')
        return 
$this->renderInput();
    
$output=array(
        
'{label}'=>$this->renderLabel(),
        
'{input}'=>$this->renderInput(),
        
'{hint}'=>$this->renderHint(),
        
'{error}'=>$this->getParent()->showErrorSummary '' $this->renderError(),
    );
    return 
strtr($this->layout,$output);
}

渲染这个输入元素的所有内容。 默认实现只是返回renderLabel,renderInput,renderHint的结果。 当CForm::showErrorSummary为false时, 也会调用renderError在单个的输入元素后显示错误信息。

renderError() 方法
public string renderError()
{return} string 渲染结果
源码: framework/web/form/CFormInputElement.php#228 (显示)
public function renderError()
{
    
$parent=$this->getParent();
    return 
$parent->getActiveFormWidget()->error($parent->getModel(), $this->name$this->errorOptions$this->enableAjaxValidation$this->enableClientValidation);
}

渲染这个输入元素的错误显示。 默认实现返回CHtml::error的结果。

renderHint() 方法
public string renderHint()
{return} string 渲染结果
源码: framework/web/form/CFormInputElement.php#239 (显示)
public function renderHint()
{
    return 
$this->hint===null '' '<div class="hint">'.$this->hint.'</div>';
}

渲染这个输入元素的提示文本。 默认实现返回一个关闭在一个HTML标签中的hint属性值。

renderInput() 方法
public string renderInput()
{return} string 渲染结果
源码: framework/web/form/CFormInputElement.php#202 (显示)
public function renderInput()
{
    if(isset(
self::$coreTypes[$this->type]))
    {
        
$method=self::$coreTypes[$this->type];
        if(
strpos($method,'List')!==false)
            return 
CHtml::$method($this->getParent()->getModel(), $this->name$this->items$this->attributes);
        else
            return 
CHtml::$method($this->getParent()->getModel(), $this->name$this->attributes);
    }
    else
    {
        
$attributes=$this->attributes;
        
$attributes['model']=$this->getParent()->getModel();
        
$attributes['attribute']=$this->name;
        
ob_start();
        
$this->getParent()->getOwner()->widget($this->type$attributes);
        return 
ob_get_clean();
    }
}

渲染输入元素。 默认实现返回适当的CHtml方法或挂件。

renderLabel() 方法
public string renderLabel()
{return} string 渲染结果
源码: framework/web/form/CFormInputElement.php#182 (显示)
public function renderLabel()
{
    
$options = array(
        
'label'=>$this->getLabel(),
        
'required'=>$this->getRequired()
    );

    if(!empty(
$this->attributes['id']))
    {
        
$options['for'] = $this->attributes['id'];
    }

    return 
CHtml::activeLabel($this->getParent()->getModel(), $this->name$options);
}

渲染这个输入元素的标签。Renders the label for this input. 默认实现返回activeLabelEx的结果。

setLabel() 方法
public void setLabel(string $value)
$value string 输入元素的标签
源码: framework/web/form/CFormInputElement.php#152 (显示)
public function setLabel($value)
{
    
$this->_label=$value;
}

setRequired() 方法
public void setRequired(boolean $value)
$value boolean 这个输入元素是否为必须的。
源码: framework/web/form/CFormInputElement.php#132 (显示)
public function setRequired($value)
{
    
$this->_required=$value;
}

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.