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

CFormButtonElement

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

CFormButtonElement can represent the following types of button based on type property: The type property can also be a class name or a path alias to the class. In this case, the button is generated using a widget of the specified class. Note, the widget must have a property called "name".

Because CFormElement is an ancestor class of CFormButtonElement, 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 button 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 button types (alias=>CHtml method name) CFormButtonElement
label string the label of this button. CFormButtonElement
name string name of this button CFormButtonElement
on string Returns a value indicating under which scenarios this button is visible. CFormButtonElement
parent mixed the direct parent of this element. CFormElement
type string the type of this button. CFormButtonElement
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
getOn() Returns a value indicating under which scenarios this button is visible. CFormButtonElement
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() Returns this button. CFormButtonElement
setOn() Sets scenario names separated by commas. CFormButtonElement
setVisible() Sets whether this element is visible and should be rendered. CFormElement

受保护的方法

隐藏继承的方法

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

属性详情

coreTypes 属性
public static array $coreTypes;

Core button types (alias=>CHtml method name)

label 属性
public string $label;

the label of this button. This property is ignored when a widget is used to generate the button.

name 属性
public string $name;

name of this button

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

Returns a value indicating under which scenarios this button is visible. If the value is empty, it means the button is visible under all scenarios. Otherwise, only when the model is in the scenario whose name can be found in this value, will the button be visible. See CModel::scenario for more information about model scenarios.

type 属性
public string $type;

the type of this button. This can be a class name, a path alias of a class name, or a button type alias (submit, button, image, reset, link, htmlButton, htmlSubmit, htmlReset).

方法详情

evaluateVisible() 方法
protected boolean evaluateVisible()
{return} boolean whether this element is visible.
源码: framework/web/form/CFormButtonElement.php#134 (显示)
protected function evaluateVisible()
{
    return empty(
$this->_on) || in_array($this->getParent()->getModel()->getScenario(),$this->_on);
}

Evaluates the visibility of this element. This method will check the on property to see if the model is in a scenario that should have this string displayed.

getOn() 方法
public string getOn()
{return} string scenario names separated by commas. Defaults to null.
源码: framework/web/form/CFormButtonElement.php#79 (显示)
public function getOn()
{
    return 
$this->_on;
}

Returns a value indicating under which scenarios this button is visible. If the value is empty, it means the button is visible under all scenarios. Otherwise, only when the model is in the scenario whose name can be found in this value, will the button be visible. See CModel::scenario for more information about model scenarios.

render() 方法
public string render()
{return} string the rendering result
源码: framework/web/form/CFormButtonElement.php#96 (显示)
public function render()
{
    
$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')
            return 
CHtml::imageButton(isset($attributes['src']) ? $attributes['src'] : '',$attributes);
        else
            return 
CHtml::$method($this->label,$attributes);
    }
    else
    {
        
$attributes['name']=$this->name;
        
ob_start();
        
$this->getParent()->getOwner()->widget($this->type$attributes);
        return 
ob_get_clean();
    }
}

Returns this button.

setOn() 方法
public void setOn(string $value)
$value string scenario names separated by commas.
源码: framework/web/form/CFormButtonElement.php#87 (显示)
public function setOn($value)
{
    
$this->_on=preg_split('/[\s,]+/',$value,-1,PREG_SPLIT_NO_EMPTY);
}