PHP Класс Prado\Web\UI\TControl

TControl is the base class for all components on a page hierarchy. It implements the following features for UI-related functionalities: - databinding feature - parent and child relationship - naming container and containee relationship - viewstate and controlstate features - rendering scheme - control lifecycles A property can be data-bound with an expression. By calling {@link dataBind}, expressions bound to properties will be evaluated and the results will be set to the corresponding properties. Parent and child relationship determines how the presentation of controls are enclosed within each other. A parent will determine where to place the presentation of its child controls. For example, a TPanel will enclose all its child controls' presentation within a div html tag. A control's parent can be obtained via {@link getParent Parent} property, and its {@link getControls Controls} property returns a list of the control's children, including controls and static texts. The property can be manipulated like an array for adding or removing a child (see {@link TList} for more details). A naming container control implements INamingContainer and ensures that its containee controls can be differentiated by their ID property values. Naming container and containee realtionship specifies a protocol to uniquely identify an arbitrary control on a page hierarchy by an ID path (concatenation of all naming containers' IDs and the target control's ID). Viewstate and controlstate are two approaches to preserve state across page postback requests. ViewState is mainly related with UI specific state and can be disabled if not needed. ControlState represents crucial logic state and cannot be disabled. A control is rendered via its {@link render()} method (the method is invoked by the framework.) Descendant control classes may override this method for customized rendering. By default, {@link render()} invokes {@link renderChildren()} which is responsible for rendering of children of the control. Control's {@link getVisible Visible} property governs whether the control should be rendered or not. Each control on a page will undergo a series of lifecycles, including control construction, Init, Load, PreRender, Render, and OnUnload. They work together with page lifecycles to process a page request.
С версии: 3.0
Автор: Qiang Xue ([email protected])
Наследование: extends Prado\TApplicationComponent, implements Prado\Web\UI\IRenderable, implements Prado\Web\UI\IBindable
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__get ( $name ) : mixed Returns a property value by name or a control by ID.
__isset ( $name ) : boolean Checks for the existance of a property value by name or a control by ID.
addParsedObject ( $object ) Adds the object instantiated on a template to the child control collection.
addedControl ( $control ) Adds a control into the child collection of the control.
applyStyleSheetSkin ( $page ) Applies a stylesheet skin to a control.
autoBindProperty ( $name, $expression ) Sets up the binding between a property (or property path) and an expression.
bindProperty ( $name, $expression ) Sets up the binding between a property (or property path) and an expression.
broadcastEvent ( $name, $sender, $param ) Broadcasts an event.
bubbleEvent ( $sender, $param ) : boolean This method responds to a bubbled event.
clearNamingContainer ( ) Resets the control as a naming container.
clearViewState ( $key ) Clears a viewstate value.
convertUniqueIdToClientId ( $uniqueID ) : string Converts a unique ID to a client ID.
createChildControls ( ) Creates child controls.
dataBind ( ) Performs the databinding for this control.
ensureChildControls ( ) Ensures child controls are created.
findControl ( $id ) : TControl | null Finds a control by ID path within the current naming container.
findControlsByID ( $id ) : array Finds all child and grand-child controls with the specified ID.
findControlsByType ( $type, $strict = true ) : array Finds all child and grand-child controls that are of the specified type.
focus ( ) Sets input focus to this control.
getAdapter ( ) : TControlAdapter
getAllowChildControls ( ) : boolean
getAttribute ( $name ) : string
getAttributes ( ) : TAttributeCollection Returns the list of custom attributes.
getClientID ( ) : string Returns the client ID of the control.
getControls ( ) : TControlCollection
getCustomData ( ) : mixed Returns custom data associated with this control.
getEnableTheming ( ) : boolean
getEnableViewState ( $checkParents = false ) : boolean
getEnabled ( $checkParents = false ) : boolean Returns a value indicating whether the control is enabled.
getHasAdapter ( ) : boolean
getHasAttributes ( ) : boolean
getHasChildInitialized ( ) : boolean
getHasControls ( ) : boolean
getHasInitialized ( ) : boolean
getHasLoaded ( ) : boolean
getHasLoadedPostData ( ) : boolean
getHasPreRendered ( ) : boolean
getID ( $hideAutoID = true ) : string Returns the id of the control.
getIsSkinApplied ( )
getNamingContainer ( ) : TControl
getPage ( ) : TPage
getParent ( ) : TControl
getRegisteredObject ( $name ) : mixed Returns the named registered object.
getSkinID ( ) : string
getSourceTemplateControl ( ) : TTemplateControl
getTemplateControl ( ) : TTemplateControl
getUniqueID ( ) : string Returns a unique ID that identifies the control in the page hierarchy.
getViewState ( $key, $defaultValue = null ) : mixed Returns a viewstate value.
getVisible ( $checkParents = true ) : boolean Checks if a control is visible.
hasAttribute ( $name ) : boolean
isObjectRegistered ( $name ) : boolean
loadState ( ) This method is invoked right after the control has loaded its state.
onDataBinding ( $param ) Raises 'OnDataBinding' event.
onInit ( $param ) This method is invoked when the control enters 'OnInit' stage.
onLoad ( $param ) This method is invoked when the control enters 'OnLoad' stage.
onPreRender ( $param ) This method is invoked when the control enters 'OnPreRender' stage.
onUnload ( $param ) This method is invoked when the control enters 'OnUnload' stage.
registerObject ( $name, $object ) Registers an object by a name.
removeAttribute ( $name ) : string Removes the named attribute.
removedControl ( $control ) Removes a control from the child collection of the control.
render ( $writer ) Renders the control.
renderChildren ( $writer ) Renders the children of the control.
renderControl ( $writer ) Renders the control.
saveState ( ) This method is invoked when control state is to be saved.
setAdapter ( TControlAdapter $adapter )
setAttribute ( $name, $value ) Sets a custom control attribute.
setCustomData ( $value ) Associates custom data with this control.
setEnableTheming ( $value )
setEnableViewState ( $value )
setEnabled ( $value )
setID ( $id )
setPage ( $page ) Sets the page for a control.
setSkinID ( $value )
setTemplateControl ( $control ) Sets the control whose template contains this control.
setViewState ( $key, $value, $defaultValue = null ) Sets a viewstate value.
setVisible ( $value )
trackViewState ( $enabled ) Sets a value indicating whether we should keep data in viewstate.
unbindProperty ( $name ) Breaks the binding between a property (or property path) and an expression.
unregisterObject ( $name ) Unregisters an object by name.

Защищенные методы

Метод Описание
autoDataBindProperties ( ) Auto databinding properties of the control.
clearChildState ( ) Clears up the child state data.
clearControlState ( $key ) Clears a controlstate value.
createControlCollection ( ) : TControlCollection Creates a control collection object that is to be used to hold child controls
dataBindChildren ( ) Databinding child controls.
dataBindProperties ( ) Databinding properties of the control.
getChildControlsCreated ( ) : boolean
getControlStage ( ) : integer Gets the lifecycle step the control is currently at.
getControlState ( $key, $defaultValue = null ) : mixed Returns a controlstate value.
initRecursive ( $namingContainer = null ) Performs the Init step for the control and all its child controls.
isDescendentOf ( $ancestor ) : boolean
loadRecursive ( ) Performs the Load step for the control and all its child controls.
loadStateRecursive ( &$state, $needViewState = true ) Loads state (viewstate and controlstate) into a control and its children.
preRenderRecursive ( ) Performs the PreRender step for the control and all its child controls.
raiseBubbleEvent ( $sender, $param ) Invokes the parent's bubbleEvent method.
saveStateRecursive ( $needViewState = true ) : array Saves all control state (viewstate and controlstate) as a collection.
setChildControlsCreated ( $value ) Sets a value indicating whether child controls are created.
setControlStage ( $value ) Sets the lifecycle step the control is currently at.
setControlState ( $key, $value, $defaultValue = null ) Sets a controlstate value.
traverseChildControls ( $param, $preCallback = null, $postCallback = null ) Traverse the whole control hierarchy rooted at this control.
unloadRecursive ( ) Performs the Unload step for the control and all its child controls.

Приватные методы

Метод Описание
broadcastEventInternal ( $name, $sender, $param ) Recursively broadcasts an event.
clearCachedUniqueID ( $recursive ) Clears the cached UniqueID.
clearNameTable ( ) Clears the list of the controls whose IDs are managed by the specified naming container.
fillNameTable ( $container, $controls ) Updates the list of the controls whose IDs are managed by the specified naming container.
generateAutomaticID ( ) Generates an automatic ID for the control.

Описание методов

__get() публичный Метод

This overrides the parent implementation by allowing accessing a control via its ID using the following syntax, $menuBar=$this->menuBar; Note, the control must be configured in the template with explicit ID. If the name matches both a property and a control ID, the control ID will take the precedence.
См. также: registerObject
public __get ( $name ) : mixed
Результат mixed the property value or the target control

__isset() публичный Метод

This overrides the parent implementation by allowing checking for the existance of a control via its ID using the following syntax, $menuBarExists = isset($this->menuBar); Do not call this method. This is a PHP magic method that we override to allow using isset() to detect if a component property is set or not. Note, the control must be configured in the template with explicit ID. If the name matches both a property and a control ID, the control ID will take the precedence.
См. также: __get
public __isset ( $name ) : boolean
Результат boolean wether the control or property exists

addParsedObject() публичный Метод

This method overrides the parent implementation. Only framework developers and control developers should use this method.
См. также: createdOnTemplate
public addParsedObject ( $object )

addedControl() публичный Метод

Control lifecycles will be caught up during the addition. Only framework developers should use this method.
public addedControl ( $control )

applyStyleSheetSkin() публичный Метод

Applies a stylesheet skin to a control.
public applyStyleSheetSkin ( $page )

autoBindProperty() публичный Метод

Unlike regular databinding, the expression bound by this method is automatically evaluated during {@link prerenderRecursive()}. The context of the expression is the template control (or the control itself if it is a page).
public autoBindProperty ( $name, $expression )

autoDataBindProperties() защищенный Метод

Auto databinding properties of the control.
protected autoDataBindProperties ( )

bindProperty() публичный Метод

The context of the expression is the template control (or the control itself if it is a page).
public bindProperty ( $name, $expression )

broadcastEvent() публичный Метод

The event will be sent to all controls on the current page hierarchy. If a control defines the event, the event will be raised for the control. If a control implements {@link IBroadcastEventReceiver}, its {@link IBroadcastEventReceiver::broadcastEventReceived broadcastEventReceived()} method will be invoked which gives the control a chance to respond to the event. For example, when broadcasting event 'OnClick', all controls having 'OnClick' event will have this event raised, and all controls implementing {@link IBroadcastEventReceiver} will also have its {@link IBroadcastEventReceiver::broadcastEventReceived broadcastEventReceived()} invoked.
public broadcastEvent ( $name, $sender, $param )

bubbleEvent() публичный Метод

This method should be overriden to provide customized response to a bubbled event. Check the type of event parameter to determine what event is bubbled currently.
См. также: raiseBubbleEvent
public bubbleEvent ( $sender, $param ) : boolean
Результат boolean true if the event bubbling is handled and no more bubbling.

clearChildState() закрытый защищенный Метод

After a control loads its state, those state that do not belong to any existing child controls are stored as child state. This method will remove these state. Only frameworker developers and control developers should use this method.
final protected clearChildState ( )

clearControlState() защищенный Метод

Clears a controlstate value.
protected clearControlState ( $key )

clearNamingContainer() публичный Метод

Only framework developers should use this method.

clearViewState() публичный Метод

Clears a viewstate value.
public clearViewState ( $key )

convertUniqueIdToClientId() публичный статический Метод

Converts a unique ID to a client ID.
public static convertUniqueIdToClientId ( $uniqueID ) : string
Результат string the client ID of the control

createChildControls() публичный Метод

This method can be overriden for controls who want to have their controls. Do not call this method directly. Instead, call {@link ensureChildControls} to ensure child controls are created only once.
public createChildControls ( )

createControlCollection() защищенный Метод

Creates a control collection object that is to be used to hold child controls
См. также: getControls
protected createControlCollection ( ) : TControlCollection
Результат TControlCollection control collection

dataBind() публичный Метод

Performs the databinding for this control.
public dataBind ( )

dataBindChildren() защищенный Метод

Databinding child controls.
protected dataBindChildren ( )

dataBindProperties() защищенный Метод

Databinding properties of the control.
protected dataBindProperties ( )

ensureChildControls() публичный Метод

If child controls are not created yet, this method will invoke {@link createChildControls} to create them.
public ensureChildControls ( )

findControl() публичный Метод

The current naming container is either the control itself if it implements {@link INamingContainer} or the control's naming container. The ID path is an ID sequence separated by {@link TControl::ID_SEPARATOR}. For example, 'Repeater1.Item1.Button1' looks for a control with ID 'Button1' whose naming container is 'Item1' whose naming container is 'Repeater1'.
public findControl ( $id ) : TControl | null
Результат TControl | null the control found, null if not found

findControlsByID() публичный Метод

Note, this method is different from {@link findControl} in that it searches through all controls that have this control as the ancestor while {@link findcontrol} only searches through controls that have this control as the direct naming container.
public findControlsByID ( $id ) : array
Результат array list of controls found

findControlsByType() публичный Метод

Finds all child and grand-child controls that are of the specified type.
public findControlsByType ( $type, $strict = true ) : array
Результат array list of controls found

focus() публичный Метод

Sets input focus to this control.
public focus ( )

getAdapter() публичный Метод

public getAdapter ( ) : TControlAdapter
Результат TControlAdapter control adapter. Null if not exists.

getAllowChildControls() публичный Метод

public getAllowChildControls ( ) : boolean
Результат boolean whether body contents are allowed for this control. Defaults to true.

getAttribute() публичный Метод

public getAttribute ( $name ) : string
Результат string attribute value, null if attribute does not exist

getAttributes() публичный Метод

Custom attributes are name-value pairs that may be rendered as HTML tags' attributes.
public getAttributes ( ) : TAttributeCollection
Результат Prado\Collections\TAttributeCollection the list of custom attributes

getChildControlsCreated() закрытый защищенный Метод

final protected getChildControlsCreated ( ) : boolean
Результат boolean whether child controls have been created

getClientID() публичный Метод

The client ID can be used to uniquely identify the control in client-side scripts (such as JavaScript). Do not rely on the explicit format of the return ID.
public getClientID ( ) : string
Результат string the client ID of the control

getControlStage() защищенный Метод

This method should only be used by control developers.
protected getControlStage ( ) : integer
Результат integer the lifecycle step the control is currently at. The value can be CS_CONSTRUCTED, CS_CHILD_INITIALIZED, CS_INITIALIZED, CS_STATE_LOADED, CS_LOADED, CS_PRERENDERED.

getControlState() защищенный Метод

This function is mainly used in defining getter functions for control properties that must be kept in controlstate.
protected getControlState ( $key, $defaultValue = null ) : mixed
Результат mixed the controlstate value corresponding to $key

getControls() публичный Метод

public getControls ( ) : TControlCollection
Результат TControlCollection the child control collection

getCustomData() публичный Метод

A control may be associated with some custom data for various purposes. For example, a button may be associated with a string to identify itself in a generic OnClick event handler.
public getCustomData ( ) : mixed
Результат mixed custom data associated with this control. Defaults to null.

getEnableTheming() публичный Метод

public getEnableTheming ( ) : boolean
Результат boolean whether theming is enabled for this control. The theming is enabled if the control and all its parents have it enabled.

getEnableViewState() публичный Метод

public getEnableViewState ( $checkParents = false ) : boolean
Результат boolean whether viewstate is enabled

getEnabled() публичный Метод

A control is enabled if it allows client user interaction. If $checkParents is true, all parent controls will be checked, and unless they are all enabled, false will be returned. The property Enabled is mainly used for {@link TWebControl} derived controls.
public getEnabled ( $checkParents = false ) : boolean
Результат boolean whether the control is enabled.

getHasAdapter() публичный Метод

public getHasAdapter ( ) : boolean
Результат boolean whether there is an adapter for this control

getHasAttributes() публичный Метод

public getHasAttributes ( ) : boolean
Результат boolean whether the control has custom attributes

getHasChildInitialized() публичный Метод

public getHasChildInitialized ( ) : boolean
Результат boolean true if the child control has been initialized.

getHasControls() публичный Метод

public getHasControls ( ) : boolean
Результат boolean whether the control has child controls

getHasInitialized() публичный Метод

public getHasInitialized ( ) : boolean
Результат boolean true if the onInit event has raised.

getHasLoaded() публичный Метод

public getHasLoaded ( ) : boolean
Результат boolean true if the onLoad event has raised.

getHasLoadedPostData() публичный Метод

public getHasLoadedPostData ( ) : boolean
Результат boolean true if the control has loaded post data.

getHasPreRendered() публичный Метод

public getHasPreRendered ( ) : boolean
Результат boolean true if onPreRender event has raised.

getID() публичный Метод

Control ID can be either manually set or automatically generated. If $hideAutoID is true, automatically generated ID will be returned as an empty string.
public getID ( $hideAutoID = true ) : string
Результат string the ID of the control

getIsSkinApplied() публичный Метод

public getIsSkinApplied ( )

getNamingContainer() публичный Метод

public getNamingContainer ( ) : TControl
Результат TControl the naming container of this control

getPage() публичный Метод

public getPage ( ) : TPage
Результат TPage the page that contains this control

getParent() публичный Метод

public getParent ( ) : TControl
Результат TControl the parent of this control

getRegisteredObject() публичный Метод

A component with explicit ID on a template will be registered to the template owner. This method allows you to obtain this component with the ID.
public getRegisteredObject ( $name ) : mixed
Результат mixed the named registered object. Null if object is not found.

getSkinID() публичный Метод

public getSkinID ( ) : string
Результат string the skin ID of this control, '' if not set

getSourceTemplateControl() публичный Метод

public getSourceTemplateControl ( ) : TTemplateControl
Результат TTemplateControl the control whose template is loaded from some external storage, such as file, db, and whose template ultimately contains this control.

getTemplateControl() публичный Метод

public getTemplateControl ( ) : TTemplateControl
Результат TTemplateControl the control whose template contains this control

getUniqueID() публичный Метод

A unique ID is the contenation of all naming container controls' IDs and the control ID. These IDs are separated by '$' character. Control users should not rely on the specific format of UniqueID, however.
public getUniqueID ( ) : string
Результат string a unique ID that identifies the control in the page hierarchy

getViewState() публичный Метод

This function is very useful in defining getter functions for component properties that must be kept in viewstate.
public getViewState ( $key, $defaultValue = null ) : mixed
Результат mixed the viewstate value corresponding to $key

getVisible() публичный Метод

If parent check is required, then a control is visible only if the control and all its ancestors are visible.
public getVisible ( $checkParents = true ) : boolean
Результат boolean whether the control is visible (default=true).

hasAttribute() публичный Метод

public hasAttribute ( $name ) : boolean
Результат boolean whether the named attribute exists

initRecursive() защищенный Метод

Only framework developers should use this method.
protected initRecursive ( $namingContainer = null )

isDescendentOf() закрытый защищенный Метод

final protected isDescendentOf ( $ancestor ) : boolean
Результат boolean if the control is a descendent (parent, parent of parent, etc.) of the specified control

isObjectRegistered() публичный Метод

См. также: registerObject
public isObjectRegistered ( $name ) : boolean
Результат boolean whether an object has been registered with the name

loadRecursive() защищенный Метод

Only framework developers should use this method.
protected loadRecursive ( )

loadState() публичный Метод

You can override this method to initialize data from the control state. Parent implementation must be invoked.
public loadState ( )

loadStateRecursive() защищенный Метод

This method should only be used by framework developers.
protected loadStateRecursive ( &$state, $needViewState = true )

onDataBinding() публичный Метод

This method is invoked when {@link dataBind} is invoked.
public onDataBinding ( $param )

onInit() публичный Метод

The method raises 'OnInit' event. If you override this method, be sure to call the parent implementation so that the event handlers can be invoked.
public onInit ( $param )

onLoad() публичный Метод

The method raises 'OnLoad' event. If you override this method, be sure to call the parent implementation so that the event handlers can be invoked.
public onLoad ( $param )

onPreRender() публичный Метод

The method raises 'OnPreRender' event. If you override this method, be sure to call the parent implementation so that the event handlers can be invoked.
public onPreRender ( $param )

onUnload() публичный Метод

The method raises 'OnUnload' event. If you override this method, be sure to call the parent implementation so that the event handlers can be invoked.
public onUnload ( $param )

preRenderRecursive() защищенный Метод

Only framework developers should use this method.
protected preRenderRecursive ( )

raiseBubbleEvent() защищенный Метод

A control who wants to bubble an event must call this method in its onEvent method.
См. также: bubbleEvent
protected raiseBubbleEvent ( $sender, $param )

registerObject() публичный Метод

A registered object can be accessed like a public member variable. This method should only be used by framework and control developers.
См. также: __get
public registerObject ( $name, $object )

removeAttribute() публичный Метод

Removes the named attribute.
public removeAttribute ( $name ) : string
Результат string attribute value removed, null if attribute does not exist.

removedControl() публичный Метод

Only framework developers should use this method.
public removedControl ( $control )

render() публичный Метод

This method is invoked by {@link renderControl} when the control is visible. You can override this method to provide customized rendering of the control. By default, the control simply renders all its child contents.
public render ( $writer )

renderChildren() публичный Метод

This method iterates through all child controls and static text strings and renders them in order.
public renderChildren ( $writer )

renderControl() публичный Метод

Only when the control is visible will the control be rendered.
public renderControl ( $writer )

saveState() публичный Метод

You can override this method to do last step state saving. Parent implementation must be invoked.
public saveState ( )

saveStateRecursive() защищенный Метод

This method should only be used by framework developers.
protected saveStateRecursive ( $needViewState = true ) : array
Результат array the collection of the control state (including its children's state).

setAdapter() публичный Метод

public setAdapter ( TControlAdapter $adapter )
$adapter TControlAdapter

setAttribute() публичный Метод

Sets a custom control attribute.
public setAttribute ( $name, $value )

setChildControlsCreated() закрытый защищенный Метод

If false, any existing child controls will be cleared up.
final protected setChildControlsCreated ( $value )

setControlStage() защищенный Метод

This method should only be used by control developers.
protected setControlStage ( $value )

setControlState() защищенный Метод

This function is very useful in defining setter functions for control properties that must be kept in controlstate. Make sure that the controlstate value must be serializable and unserializable.
protected setControlState ( $key, $value, $defaultValue = null )

setCustomData() публичный Метод

Note, the custom data must be serializable and unserializable.
public setCustomData ( $value )

setEnableTheming() публичный Метод

public setEnableTheming ( $value )

setEnableViewState() публичный Метод

public setEnableViewState ( $value )

setEnabled() публичный Метод

public setEnabled ( $value )

setID() публичный Метод

public setID ( $id )

setPage() публичный Метод

Only framework developers should use this method.
public setPage ( $page )

setSkinID() публичный Метод

public setSkinID ( $value )

setTemplateControl() публичный Метод

Only framework developers should use this method.
public setTemplateControl ( $control )

setViewState() публичный Метод

This function is very useful in defining setter functions for control properties that must be kept in viewstate. Make sure that the viewstate value must be serializable and unserializable.
public setViewState ( $key, $value, $defaultValue = null )

setVisible() публичный Метод

public setVisible ( $value )

trackViewState() публичный Метод

When it is false, data saved via setViewState() will not be persisted. By default, it is true, meaning data will be persisted across postbacks.
public trackViewState ( $enabled )

traverseChildControls() защищенный Метод

Callback function may be invoked for each control being visited. A pre-callback is invoked before traversing child controls; A post-callback is invoked after traversing child controls. Callback functions can be global functions or class methods. They must be of the following signature: function callback_func($control,$param) {...} where $control refers to the control being visited and $param is the parameter that is passed originally when calling this traverse function.
protected traverseChildControls ( $param, $preCallback = null, $postCallback = null )

unbindProperty() публичный Метод

Breaks the binding between a property (or property path) and an expression.
public unbindProperty ( $name )

unloadRecursive() защищенный Метод

Only framework developers should use this method.
protected unloadRecursive ( )

unregisterObject() публичный Метод

Unregisters an object by name.
См. также: registerObject
public unregisterObject ( $name )