system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.cubrid system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.gii system.i18n system.i18n.gettext system.logging system.test system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.form system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers zii.behaviors zii.widgets zii.widgets.grid zii.widgets.jui

CFormInputElement

system.web.form
继承 class CFormInputElement » CFormElement » CComponent
可用自 1.1
源码 framework/web/form/CFormInputElement.php
CFormInputElement represents form input element.

CFormInputElement can represent the following types of form input based on type property: The type property can also be a class name or a path alias to the class. In this case, the input is generated using a widget of the specified class. Note, the widget must have a property called "model" which expects a model object, and a property called "attribute" which expects the name of a model attribute.

Because CFormElement is an ancestor class of CFormInputElement, a value assigned to a non-existing property will be stored in attributes which will be passed as HTML attribute values to the CHtml method generating the input or initial values of the widget properties.

公共属性

隐藏继承的属性

属性类型描述被定义在
attributes array list of attributes (name=>value) for the HTML element represented by this object. CFormElement
coreTypes array Core input types (alias=>CHtml method name) CFormInputElement
enableAjaxValidation boolean whether to allow AJAX-based validation for this input. CFormInputElement
enableClientValidation boolean whether to allow client-side validation for this input. CFormInputElement
errorOptions array the options used when rendering the error part. CFormInputElement
hint string hint text of this input CFormInputElement
items array the options for this input when it is a list box, drop-down list, check box list, or radio button list. CFormInputElement
label string the label for this input. CFormInputElement
layout string the layout used to render label, input, hint and error. CFormInputElement
name string name of this input CFormInputElement
parent mixed the direct parent of this element. CFormElement
required boolean Gets the value indicating whether this input is required. CFormInputElement
type string the type of this input. CFormInputElement
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
getLabel() Returns the label for this input. If the label is not manually set, this method will call CModel::getAttributeLabel to determine the label. CFormInputElement
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
getRequired() Gets the value indicating whether this input is required. CFormInputElement
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 everything for this input. CFormInputElement
renderError() Renders the error display of this input. CFormInputElement
renderHint() Renders the hint text for this input. CFormInputElement
renderInput() Renders the input field. CFormInputElement
renderLabel() Renders the label for this input. CFormInputElement
setLabel() Sets the label for this input CFormInputElement
setRequired() Sets whether this input is required. CFormInputElement
setVisible() Sets whether this element is visible and should be rendered. CFormElement

受保护的方法

隐藏继承的方法

方法描述被定义在
evaluateVisible() Evaluates the visibility of this element. CFormInputElement

属性详情

coreTypes 属性
public static array $coreTypes;

Core input types (alias=>CHtml method name)

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

whether to allow AJAX-based validation for this input. Note that in order to use AJAX-based validation, CForm::activeForm must be configured with 'enableAjaxValidation'=>true. This property allows turning on or off AJAX-based validation for individual input fields. Defaults to true.

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

whether to allow client-side validation for this input. Note that in order to use client-side validation, CForm::activeForm must be configured with 'enableClientValidation'=>true. This property allows turning on or off client-side validation for individual input fields. Defaults to true.

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

the options used when rendering the error part. This property will be passed to the CActiveForm::error method call as its $htmlOptions parameter.

hint 属性
public string $hint;

hint text of this input

items 属性
public array $items;

the options for this input when it is a list box, drop-down list, check box list, or radio button list. Please see CHtml::listData for details of generating this property value.

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

the label for this input. If the label is not manually set, this method will call CModel::getAttributeLabel to determine the label.

layout 属性
public string $layout;

the layout used to render label, input, hint and error. They correspond to the placeholders "{label}", "{input}", "{hint}" and "{error}".

name 属性
public string $name;

name of this input

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

Gets the value indicating whether this input is required. If this property is not set explicitly, it will be determined by calling CModel::isAttributeRequired for the associated model and attribute of this input.

type 属性
public string $type;

the type of this input. This can be a widget class name, a path alias of a widget class name, or an input type alias (text, hidden, password, textarea, file, radio, checkbox, listbox, dropdownlist, checkboxlist, or radiolist). If a widget class, it must extend from CInputWidget or (@link CJuiInputWidget).

方法详情

evaluateVisible() 方法
protected boolean evaluateVisible()
{return} boolean whether this element is visible.
源码: framework/web/form/CFormInputElement.php#272 (显示)
protected function evaluateVisible()
{
    return 
$this->getParent()->getModel()->isAttributeSafe($this->name);
}

Evaluates the visibility of this element. This method will check if the attribute associated with this input is safe for the current model scenario.

getLabel() 方法
public string getLabel()
{return} string the label for this input. If the label is not manually set, this method will call CModel::getAttributeLabel to determine the label.
源码: framework/web/form/CFormInputElement.php#165 (显示)
public function getLabel()
{
    if(
$this->_label!==null)
        return 
$this->_label;
    else
        return 
$this->getParent()->getModel()->getAttributeLabel($this->name);
}

getRequired() 方法
public boolean getRequired()
{return} boolean whether this input is required.
源码: framework/web/form/CFormInputElement.php#145 (显示)
public function getRequired()
{
    if(
$this->_required!==null)
        return 
$this->_required;
    else
        return 
$this->getParent()->getModel()->isAttributeRequired($this->name);
}

Gets the value indicating whether this input is required. If this property is not set explicitly, it will be determined by calling CModel::isAttributeRequired for the associated model and attribute of this input.

render() 方法
public string render()
{return} string the complete rendering result for this input, including label, input field, hint, and error.
源码: framework/web/form/CFormInputElement.php#188 (显示)
public function render()
{
    if(
$this->type==='hidden')
        return 
$this->renderInput();
    
$output=array(
        
'{label}'=>$this->renderLabel(),
        
'{input}'=>$this->renderInput(),
        
'{hint}'=>$this->renderHint(),
        
'{error}'=>!$this->getParent()->showErrors '' $this->renderError(),
    );
    return 
strtr($this->layout,$output);
}

Renders everything for this input. The default implementation simply returns the result of renderLabel, renderInput, renderHint. When CForm::showErrorSummary is false, renderError is also called to show error messages after individual input fields.

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

Renders the error display of this input. The default implementation returns the result of CHtml::error

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

Renders the hint text for this input. The default implementation returns the hint property enclosed in a paragraph HTML tag.

renderInput() 方法
public string renderInput()
{return} string the rendering result
源码: framework/web/form/CFormInputElement.php#224 (显示)
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();
    }
}

Renders the input field. The default implementation returns the result of the appropriate CHtml method or the widget.

renderLabel() 方法
public string renderLabel()
{return} string the rendering result
源码: framework/web/form/CFormInputElement.php#206 (显示)
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. The default implementation returns the result of activeLabelEx.

setLabel() 方法
public void setLabel(string $value)
$value string the label for this input
源码: framework/web/form/CFormInputElement.php#176 (显示)
public function setLabel($value)
{
    
$this->_label=$value;
}

setRequired() 方法
public void setRequired(boolean $value)
$value boolean whether this input is required.
源码: framework/web/form/CFormInputElement.php#156 (显示)
public function setRequired($value)
{
    
$this->_required=$value;
}