Class TComponent
Direct Known Sub-classes:
TCacheDependency
, TDummyDataSource
, TList
, TMap
, TPagedDataSource
, TQueue
, TStack
, TActiveRecord
, TActiveRecordGateway
, TActiveRecordManager
, TOracleTableInfo
, TDbCommandBuilder
, TDbMetaData
, TDbTableColumn
, TDbTableInfo
, TDataGatewayCommand
, TSqlCriteria
, TTableGateway
, TDiscriminator
, TSubMap
, TParameterMap
, TParameterProperty
, TResultMap
, TResultProperty
, TSqlMapCacheModel
, TSqlMapStatement
, TSqlMapTypeHandler
, TCachingStatement
, TMappedStatement
, TSqlMapObjectCollectionTree
, TResultSetListItemParameter
, TResultSetMapItemParameter
, TPreparedStatement
, TStaticSql
, TSqlMapGateway
, TSqlMapManager
, TDbCommand
, TDbConnection
, TDbDataReader
, TDbTransaction
, Translation
, TTextWriter
, TAuthorizationRule
, TUser
, TApplication
, TApplicationConfiguration
, TApplicationComponent
, TEventParameter
, TComponentReflection
, TLogger
, TPageConfiguration
, THttpCookie
, TUri
, TUrlMappingPattern
, TAutoCompleteTemplate
, TBaseActiveControl
, TCachePageStatePersister
, TClientSideOptions
, TCompositeLiteral
, TPageStatePersister
, TSessionPageStatePersister
, TDataSourceSelectParameters
, TDataSourceView
, TFont
, TMetaTag
, THotSpot
, TListItem
, TRepeatInfo
, TStyle
, TWebControlDecorator
, TWizardSideBarTemplate
, TWizardSideBarListItemTemplate
, TWizardNavigationTemplate
, TXmlElement
TComponent class
TComponent is the base class for all PRADO components. TComponent implements the protocol of defining, using properties and events. A property is defined by a getter method, and/or a setter method. Properties can be accessed in the way like accessing normal object members. Reading or writing a property will cause the invocation of the corresponding getter or setter method, e.g., $a=$this->Text; // equivalent to $a=$this->getText();
$this->Text='abc'; // equivalent to $this->setText('abc');
The signatures of getter and setter methods are as follows, // getter, defines a readable property 'Text'
function getText() { ... }
// setter, defines a writable property 'Text', with $value being the value to be set to the property
function setText($value) { ... }
Property names are case-insensitive. It is recommended that they are written in the format of concatenated words, with the first letter of each word capitalized (e.g. DisplayMode, ItemStyle). Since Prado 3.2 a new class of javascript-friendly properties have been introduced to better deal with potential security problems like cross-site scripting issues. All the data that gets sent clientside inside a javascript block is now encoded by default. Sometimes there's the need to bypass this encoding and be able to send raw javascript code. This new class of javascript-friendly properties are identified by their name starting with 'js' (case insensitive): // getter, defines a readable property 'Text'
function getJsText() { ... }
// setter, defines a writable property 'Text', with $value being the value to be set to the property
function setJsText(TJavaScriptLiteral $value) { ... }
Js-friendly properties can be accessed using both their Js-less name and their Js-enabled name: // set some simple text as property value
$component->Text = 'text';
// set some javascript code as property value
$component->JsText = 'raw javascript';
In the first case, the property value will automatically gets encoded when sent clientside inside a javascript block. In the second case, the property will be 'marked' as being a safe javascript statement and will not be encoded when rendered inside a javascript block. This special handling makes use of the TJavaScriptLiteral class. An event is defined by the presence of a method whose name starts with 'on'. The event name is the method name and is thus case-insensitive. An event can be attached with one or several methods (called event handlers). An event can be raised by calling raiseEvent method, upon which the attached event handlers will be invoked automatically in the order they are attached to the event. Event handlers must have the following signature, function eventHandlerFuncName($sender,$param) { ... }
where $sender refers to the object who is responsible for the raising of the event, and $param refers to a structure that may contain event-specific information. To raise an event (assuming named as 'Click') of a component, use To attach an event handler to an event, use one of the following ways, $component->OnClick=$callback; // or $component->OnClick->add($callback);
The first two ways make use of the fact that $component->OnClick refers to the event handler list TList for the 'OnClick' event. The variable $callback contains the definition of the event handler that can be either a string referring to a global function name, or an array whose first element refers to an object and second element a method name/path that is reachable by the object, e.g. - 'buttonClicked' : buttonClicked($sender,$param);
- array($object,'buttonClicked') : $object->buttonClicked($sender,$param);
- array($object,'MainContent.SubmitButton.buttonClicked') :
$object->MainContent->SubmitButton->buttonClicked($sender,$param);
| Method Summary |
|
void
|
Processes an object that is created during parsing template.
|
|
void
|
Attaches an event handler to an event.
|
|
boolean
|
Determines whether a property can be read.
|
|
boolean
|
Determines whether a property can be set.
|
|
void
|
This method is invoked after the component is instantiated by a template.
|
|
boolean
|
Detaches an existing event handler.
|
|
mixed
|
Evaluates a PHP expression in the context of this control.
|
|
string
|
Evaluates a list of PHP statements.
|
|
TList
|
Returns the list of attached event handlers for an event.
|
|
mixed
|
Evaluates a property path.
|
|
boolean
|
Determines whether an event is defined.
|
|
boolean
|
|
|
boolean
|
Determines whether a property is defined.
|
|
void
|
Raises an event.
|
|
void
|
Sets a value to a property path.
|
|
void
|
__call
( string $name, mixed $params)
Calls a method.
|
|
mixed
|
Returns a property value or an event handler list by property or event name.
|
|
void
|
__set
( string $name, mixed $value)
Sets value of a component property.
|
|
void
|
Returns an array with the names of all variables of that object that should be serialized.
|
|
void
|
Do not call this method. This is a PHP magic method that will be called automatically after any unserialization; it can perform reinitialization tasks on the object.
|
| Method Details |
addParsedObject
| public void addParsedObject |
(string|TComponent $object ) |
Processes an object that is created during parsing template.
The object can be either a component or a static text string. This method can be overridden to customize the handling of newly created objects in template. Only framework developers and control developers should use this method.
| Input |
| string|TComponent | $object | text string or component parsed and instantiated in template |
| Output |
| Exception |
|
attachEventHandler
| public void attachEventHandler |
(string $name , callback $handler ) |
Attaches an event handler to an event.
The handler must be a valid PHP callback, i.e., a string referring to a global function name, or an array containing two elements with the first element being an object and the second element a method name of the object. In Prado, you can also use method path to refer to an event handler. For example, array($object,'Parent.buttonClicked') uses a method path that refers to the method $object->Parent->buttonClicked(...). The event handler must be of the following signature, function handlerName($sender,$param) {}
where $sender represents the object that raises the event, and $param is the event parameter.This is a convenient method to add an event handler. It is equivalent to getEventHandlers($name)->add($handler). For complete management of event handlers, use getEventHandlers to get the event handler list first, and then do various TList operations to append, insert or remove event handlers. You may also do these operations like getting and setting properties, e.g., $component->OnClick[]=array($object,'buttonClicked');
$component->OnClick->insertAt(0,array($object,'buttonClicked'));
which are equivalent to the following
$component->getEventHandlers('OnClick')->insertAt(0,array($object,'buttonClicked'));
| Input |
| string | $name | the event name |
| callback | $handler | the event handler |
| Output |
| Exception |
| throws | TInvalidOperationException if the event does not exist |
|
canGetProperty
| public boolean canGetProperty |
(string $name ) |
Determines whether a property can be read.
A property can be read if the class has a getter method for the property name. Note, property name is case-insensitive.
| Input |
| string | $name | the property name |
| Output |
|
boolean
| whether the property can be read |
| Exception |
|
canSetProperty
| public boolean canSetProperty |
(string $name ) |
Determines whether a property can be set.
A property can be written if the class has a setter method for the property name. Note, property name is case-insensitive.
| Input |
| string | $name | the property name |
| Output |
|
boolean
| whether the property can be written |
| Exception |
|
createdOnTemplate
| public void createdOnTemplate |
(TComponent $parent ) |
This method is invoked after the component is instantiated by a template.
When this method is invoked, the component's properties have been initialized. The default implementation of this method will invoke the potential parent component's addParsedObject. This method can be overridden.
| Input |
| TComponent | $parent | potential parent of this control |
| Output |
| Exception |
|
detachEventHandler
| public boolean detachEventHandler |
(string $name , callback $handler ) |
Detaches an existing event handler.
This method is the opposite of attachEventHandler.
| Input |
| string | $name | event name |
| callback | $handler | the event handler to be removed |
| Output |
|
boolean
| if the removal is successful |
| Exception |
|
evaluateExpression
| public mixed evaluateExpression |
( $expression ) |
Evaluates a PHP expression in the context of this control.
| Input |
| $expression | |
| Output |
|
mixed
| the expression result |
| Exception |
| throws | TInvalidOperationException if the expression is invalid |
|
evaluateStatements
| public string evaluateStatements |
(string $statements ) |
Evaluates a list of PHP statements.
| Input |
| string | $statements | PHP statements |
| Output |
|
string
| content echoed or printed by the PHP statements |
| Exception |
| throws | TInvalidOperationException if the statements are invalid |
|
getEventHandlers
| public TList getEventHandlers |
( $name ) |
Returns the list of attached event handlers for an event.
| Input |
| $name | |
| Output |
|
TList
| list of attached event handlers for an event |
| Exception |
| throws | TInvalidOperationException if the event is not defined |
|
getSubProperty
| public mixed getSubProperty |
(string $path ) |
Evaluates a property path.
A property path is a sequence of property names concatenated by '.' character. For example, 'Parent.Page' refers to the 'Page' property of the component's 'Parent' property value (which should be a component also).
| Input |
| string | $path | property path |
| Output |
|
mixed
| the property path value |
| Exception |
|
hasEvent
| public boolean hasEvent |
(string $name ) |
Determines whether an event is defined.
An event is defined if the class has a method whose name is the event name prefixed with 'on'. Note, event name is case-insensitive.
| Input |
| string | $name | the event name |
| Output |
| Exception |
|
hasEventHandler
| public boolean hasEventHandler |
( $name ) |
| Input |
| $name | |
| Output |
|
boolean
| whether an event has been attached one or several handlers |
| Exception |
|
hasProperty
| public boolean hasProperty |
(string $name ) |
Determines whether a property is defined.
A property is defined if there is a getter or setter method defined in the class. Note, property names are case-insensitive.
| Input |
| string | $name | the property name |
| Output |
|
boolean
| whether the property is defined |
| Exception |
|
raiseEvent
| public void raiseEvent |
(string $name , mixed $sender , TEventParameter $param ) |
Raises an event.
This method represents the happening of an event and will invoke all attached event handlers for the event.
| Input |
| string | $name | the event name |
| mixed | $sender | the event sender object |
| TEventParameter | $param | the event parameter |
| Output |
| Exception |
| throws | TInvalidDataValueException If an event handler is invalid |
| throws | TInvalidOperationException if the event is undefined |
|
setSubProperty
| public void setSubProperty |
(string $path , mixed $value ) |
Sets a value to a property path.
A property path is a sequence of property names concatenated by '.' character. For example, 'Parent.Page' refers to the 'Page' property of the component's 'Parent' property value (which should be a component also).
| Input |
| string | $path | property path |
| mixed | $value | the property path value |
| Output |
| Exception |
|
__call
| public void __call |
(string $name , mixed $params ) |
Calls a method.
Do not call this method. This is a PHP magic method that we override to allow using the following syntax to call a property setter or getter. $this->getPropertyName($value); // if there's a $this->getjsPropertyName() method
$this->setPropertyName($value); // if there's a $this->setjsPropertyName() method
| Input |
| string | $name | the getter or setter method name |
| mixed | $params | method call parameters |
| Output |
| Exception |
| throws | TInvalidOperationException If the property is not defined or read-only. |
|
__get
| public mixed __get |
(string $name ) |
Returns a property value or an event handler list by property or event name.
Do not call this method. This is a PHP magic method that we override to allow using the following syntax to read a property: $value=$component->PropertyName;
$value=$component->jsPropertyName; // return JavaScript literal
and to obtain the event handler list for an event, $eventHandlerList=$component->EventName;
| Input |
| string | $name | the property name or the event name |
| Output |
|
mixed
| the property value or the event handler list |
| Exception |
| throws | TInvalidOperationException if the property/event is not defined. |
|
__set
| public void __set |
(string $name , mixed $value ) |
Sets value of a component property.
Do not call this method. This is a PHP magic method that we override to allow using the following syntax to set a property or attach an event handler. $this->PropertyName=$value;
$this->jsPropertyName=$value; // $value will be treated as a JavaScript literal
$this->EventName=$handler;
| Input |
| string | $name | the property name or event name |
| mixed | $value | the property value or event handler |
| Output |
| Exception |
| throws | TInvalidOperationException If the property is not defined or read-only. |
|
__sleep
Returns an array with the names of all variables of that object that should be serialized.
Do not call this method. This is a PHP magic method that will be called automatically prior to any serialization.
|
__wakeup
Do not call this method. This is a PHP magic method that will be called automatically after any unserialization; it can perform reinitialization tasks on the object.
|
|