Class TComponent
Direct Known Sub-classes:
TTextWriter
, TClientSideOptions
, TBaseActiveControl
, TAutoCompleteTemplate
, TStyle
, TFont
, THotSpot
, TListItem
, TDataSourceSelectParameters
, TDataSourceView
, TRepeatInfo
, TMetaTag
, TWizardSideBarTemplate
, TWizardSideBarListItemTemplate
, TWizardNavigationTemplate
, TCachePageStatePersister
, TSessionPageStatePersister
, TPageStatePersister
, TCompositeLiteral
, TUrlMappingPattern
, TPageConfiguration
, THttpCookie
, TUri
, TXmlElement
, TOracleTableInfo
, TDbTableColumn
, TDbMetaData
, TDbCommandBuilder
, TDbTableInfo
, TActiveRecordGateway
, TActiveRecord
, TActiveRecordManager
, TTableGateway
, TDataGatewayCommand
, TSqlCriteria
, TSqlMapTypeHandler
, TSqlMapGateway
, TSqlMapManager
, TPreparedStatement
, TMappedStatement
, TResultSetListItemParameter
, TResultSetMapItemParameter
, TStaticSql
, TParameterMap
, TResultMap
, TSqlMapStatement
, TDiscriminator
, TSubMap
, TResultProperty
, TSqlMapCacheModel
, TParameterProperty
, TDbDataReader
, TDbConnection
, TDbCommand
, TDbTransaction
, Translation
, TLogger
, TEventParameter
, TComponentReflection
, TPagedDataSource
, TMap
, TDummyDataSource
, TStack
, TQueue
, TList
, TCacheDependency
, TAuthorizationRule
, TUser
, TApplication
, TApplicationConfiguration
, TApplicationComponent
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). 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);
- $$component->attachEventHandler('OnClick',$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.
|
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.
|
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')->add(array($object,'buttonClicked'));
- $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 |
(mixed $expression ) |
Evaluates a PHP expression in the context of this control.
Input |
mixed | $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 |
(mixed $name ) |
Returns the list of attached event handlers for an event.
Input |
mixed | $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 |
(mixed $name ) |
Input |
mixed | $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 | TInvalidOperationException if the event is undefined |
throws | TInvalidDataValueException If an event handler is invalid |
|
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 |
|
__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;
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->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. |
|
|