Class \Prado\Web\UI\WebControls\TConditional
TConditional displays appropriate content based on the evaluation result of a PHP expression specified via \Prado\Web\UI\WebControls\setCondition. If the result is true, it instantiates the template \Prado\Web\UI\WebControls\getTrueTemplate; otherwise, the template \Prado\Web\UI\WebControls\getFalseTemplate is instantiated. The PHP expression is evaluated right before onInit stage of the control lifecycle.
Since \Prado\Web\UI\WebControls\setCondition is evaluated at a very early stage, it is recommended you set \Prado\Web\UI\WebControls\setCondition in template and the expression should not refer to objects that are available on or after 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 \Prado\Web\UI\WebControls\getTrueTemplate or \Prado\Web\UI\WebControls\getFalseTemplate, but never both. And the condition is evaluated only once.
Class hierarchy
- \Prado\Web\UI\WebControls\TConditional
- \Prado\Web\UI\TControl implements IRenderable, IBindable
- \Prado\TApplicationComponent
- \Prado\TComponent
Since: 3.1.1
public
|
addParsedObject(TComponent|string $object) : mixed
Processes an object that is created during parsing template.
This method overrides the parent implementation by removing all contents enclosed in the template tag. |
public
|
createChildControls() : mixed
Creates child controls.
This method overrides the parent implementation. It evaluates \Prado\Web\UI\WebControls\getCondition and instantiate the corresponding template. |
public
|
|
public
|
|
public
|
|
public
|
setCondition(string $value) : mixed
Sets the PHP expression to be evaluated for conditionally displaying content.
The context of the expression is the template control containing TConditional. |
public
|
|
public
|