|
Class TConditional
TConditional class.
TConditional displays appropriate content based on the evaluation result of a
PHP expression specified via setCondition Condition. If the result is
true, it instantiates the template getTrueTemplate TrueTemplate;
otherwise, the template getFalseTemplate FalseTemplate is instantiated.
The PHP expression is evaluated right before TControl::onInit() stage of the control
lifecycle.
Since setCondition Condition is evaluated at a very early stage, it
is recommended you set setCondition Condition in template and the
expression should not refer to objects that are available on or after TControl::onInit() lifecycle.
A typical usage of TConditional is shown as following:
<com:TConditional Condition="$this->User->IsGuest">
<prop:TrueTemplate>
<a href="path/to/login">Login</a>
</prop:TrueTemplate>
<prop:FalseTemplate>
<a href="path/to/logout">Logout</a>
</prop:FalseTemplate>
</com:TConditional>
TConditional is very light. It instantiates either getTrueTemplate
TrueTemplate or getFalseTemplate FalseTemplate, but never both. And the
condition is evaluated only once.
-
TComponent
-
TApplicationComponent
-
TControl
implements
IRenderable,
IBindable
-
TConditional
Methods summary
public
|
#
addParsedObject( string|TComponent $object )
Processes an object that is created during parsing template. This method
overrides the parent implementation by removing all contents enclosed in the
template tag.
Processes an object that is created during parsing template. This method
overrides the parent implementation by removing all contents enclosed in the
template tag.
Parameters
- $object
string|TComponent text string or component parsed and instantiated in template
See
Overrides
|
public
|
#
createChildControls( )
Creates child controls. This method overrides the parent implementation. It
evaluates getCondition Condition and instantiate the corresponding
template.
Creates child controls. This method overrides the parent implementation. It
evaluates getCondition Condition and instantiate the corresponding
template.
Overrides
|
public
string
|
#
getCondition( )
Returns
string the PHP expression used for determining which template to use. Defaults to
'true', meaning using TrueTemplate.
|
public
|
#
setCondition( string $value )
Sets the PHP expression to be evaluated for conditionally displaying content.
The context of the expression is the template control containing
TConditional.
Sets the PHP expression to be evaluated for conditionally displaying content.
The context of the expression is the template control containing
TConditional.
Parameters
- $value
string the PHP expression used for determining which template to use.
|
public
ITemplate
|
#
getTrueTemplate( )
Returns
ITemplate
the template applied when getCondition Condition is true.
|
public
|
#
setTrueTemplate( ITemplate $value )
Parameters
- $value
ITemplate
the template applied when getCondition Condition is true.
|
public
ITemplate
|
#
getFalseTemplate( )
Returns
ITemplate
the template applied when getCondition Condition is false.
|
public
|
#
setFalseTemplate( ITemplate $value )
Parameters
- $value
ITemplate
the template applied when getCondition Condition is false.
|
Methods inherited from TControl
__construct(),
__get(),
addToPostDataLoader(),
addedControl(),
applyStyleSheetSkin(),
autoBindProperty(),
autoDataBindProperties(),
bindProperty(),
broadcastEvent(),
bubbleEvent(),
clearChildState(),
clearControlState(),
clearNamingContainer(),
clearViewState(),
convertUniqueIdToClientId(),
createControlCollection(),
dataBind(),
dataBindChildren(),
dataBindProperties(),
ensureChildControls(),
findControl(),
findControlsByID(),
findControlsByType(),
focus(),
getAdapter(),
getAllowChildControls(),
getAttribute(),
getAttributes(),
getChildControlsCreated(),
getClientID(),
getControlStage(),
getControlState(),
getControls(),
getCustomData(),
getEnableTheming(),
getEnableViewState(),
getEnabled(),
getHasAdapter(),
getHasAttributes(),
getHasChildInitialized(),
getHasControls(),
getHasInitialized(),
getHasLoaded(),
getHasLoadedPostData(),
getHasPreRendered(),
getID(),
getIsSkinApplied(),
getNamingContainer(),
getPage(),
getParent(),
getRegisteredObject(),
getSkinID(),
getSourceTemplateControl(),
getTemplateControl(),
getUniqueID(),
getViewState(),
getVisible(),
hasAttribute(),
initRecursive(),
isDescendentOf(),
isObjectRegistered(),
loadRecursive(),
loadState(),
loadStateRecursive(),
onDataBinding(),
onInit(),
onLoad(),
onPreRender(),
onUnload(),
preRenderRecursive(),
raiseBubbleEvent(),
registerObject(),
removeAttribute(),
removedControl(),
render(),
renderChildren(),
renderControl(),
saveState(),
saveStateRecursive(),
setAdapter(),
setAttribute(),
setChildControlsCreated(),
setControlStage(),
setControlState(),
setCustomData(),
setEnableTheming(),
setEnableViewState(),
setEnabled(),
setID(),
setPage(),
setSkinID(),
setTemplateControl(),
setViewState(),
setVisible(),
trackViewState(),
traverseChildControls(),
unbindProperty(),
unloadRecursive(),
unregisterObject()
|
Methods inherited from TComponent
__call(),
__destruct(),
__isset(),
__set(),
__sleep(),
__unset(),
__wakeup(),
asa(),
attachBehavior(),
attachBehaviors(),
attachClassBehavior(),
attachEventHandler(),
canGetProperty(),
canSetProperty(),
clearBehaviors(),
createdOnTemplate(),
detachBehavior(),
detachBehaviors(),
detachClassBehavior(),
detachEventHandler(),
disableBehavior(),
disableBehaviors(),
enableBehavior(),
enableBehaviors(),
evaluateExpression(),
evaluateStatements(),
fxAttachClassBehavior(),
fxDetachClassBehavior(),
getAutoGlobalListen(),
getBehaviorsEnabled(),
getClassHierarchy(),
getEventHandlers(),
getListeningToGlobalEvents(),
getSubProperty(),
hasEvent(),
hasEventHandler(),
hasProperty(),
isa(),
listen(),
raiseEvent(),
setSubProperty(),
unlisten()
|
Constants inherited from TControl
AUTOMATIC_ID_PREFIX,
CLIENT_ID_SEPARATOR,
CS_CHILD_INITIALIZED,
CS_CONSTRUCTED,
CS_INITIALIZED,
CS_LOADED,
CS_PRERENDERED,
CS_STATE_LOADED,
ID_FORMAT,
ID_SEPARATOR,
IS_CHILD_CREATED,
IS_CREATING_CHILD,
IS_DISABLE_THEMING,
IS_DISABLE_VIEWSTATE,
IS_ID_SET,
IS_SKIN_APPLIED,
IS_STYLESHEET_APPLIED,
RF_ADAPTER,
RF_AUTO_BINDINGS,
RF_CHILD_STATE,
RF_CONTROLS,
RF_CONTROLSTATE,
RF_DATA_BINDINGS,
RF_EVENTS,
RF_NAMED_CONTROLS,
RF_NAMED_CONTROLS_ID,
RF_NAMED_OBJECTS,
RF_SKIN_ID
|
|