System
[ class tree: System ] [ index: System ] [ all elements ]

Class: TComponent

Source Location: /TComponent.php

Class Overview


TComponent class

Class Details

[line 83]
TComponent class

TComponent is the base class for all PRADO components. A component, an instance of TComponent or its descendent class, is a basic building-block in a PRADO application.

A component has

  • properties, which can be accessed by other components or functions.
  • events, which can be assigned with delegate functions. When an event happens, the corresponding delegates will be automatically invoked.
Properties and events are inheritable. They cannot be redefined. The corresponding property getter and setter methods can be overriden, however.

Components define their properties and events in component specification files. The property initial values and event handlers can be set in component class files, specification files or control's template files.

TComponent provides support for component composition and templating. A component has Children and Parent, which establishes a tree based on the parent-child relationship.

Each component has an ID that uniquely identifies itself among its siblings. Besides, each component has a UniqueID that uniquely identifies itself in the page hierarchy. You can use UniqueID to render the id or name attribute of the corresponding HTML element.

Namespace: System Properties

  • ID, string, read-only
    Gets the programmatic identifier assigned to the component. The value is unique among all the sibling components.
  • UniqueID, string, read-only
    Gets the unique, hierarchically-qualified identifier for the component. The value is unique among all components in the page/module hierarchy. It is mainly used to identify postback target and specify the id attribute of the corresponding HTML element.
  • Parent, TComponent, read-only
    Gets the component's parent component in the page/module hierarchy. Note, a page/module component has no parent and its Parent property is null.
  • Children, array, read-only
    Gets the list of children index
  • Page, TPage, read-only
    Gets the page instance that contains the component.
  • Module, TModule, read-only
    Gets the module instance that contains the component or the page containing the component.
  • User, IUser, read-only
    Gets the user object associated with the application.
  • Session, ISession, read-only
    Gets the session object associated with the application.
  • Application, TApplication, read-only
    Gets the application object.
  • Request, TRequest, read-only
    Gets the request object
  • Definition, TComponentDefinition, read-only
    Gets the definition of the component.
Events
  • OnDataBinding Occurs when the component evaluates expressions bound to its properties.




version:  v1.0, last update on 2004/08/13 21:44:52
author:  Qiang Xue <qiang.xue@gmail.com>


[ Top ]

Variables

Methods


Child classes:

TAdodb
TAdodb class
TModule
TModule class
TControl
TControl class
TListItem
TListItem class

Class Variables

$children = array()

[line 114]

children of this component



access:  protected

Type:   TComponent


[ Top ]



Class Methods


constructor __construct [line 145]

TComponent __construct( )

Constructor.

Parses specification and template to form compoent definition. Child components and body content will be constructed and configured.

To inheritors, be sure to call the parent constructor first so that the component properties and events are defined.




access:  public


Overridden in child classes as:

TModule::__construct()
Constructor.
TControl::__construct()
Constructor.
TPage::__construct()
Constructor, initiates the root to itself.
TCallbackPage::__construct()
Initialize the callback service.
THiddenField::__construct()
Constructor.
TRepeaterItem::__construct()
Constructor.
TDataGrid::__construct()
Initializes the columns list
TDataList::__construct()
Initializes the item list
TButton::__construct()
Constructor.
TCheckBox::__construct()
Constructor.
TRadioButton::__construct()
TDataListItem::__construct()
Constructor.
TFileUpload::__construct()
Constructor.
TFormLabel::__construct()
Constructor.
THyperLink::__construct()
Constructor.
TImage::__construct()
Constructor.
TImageButton::__construct()
Constructor.
TLabel::__construct()
Constructor.
TLinkButton::__construct()
Constructor.
TListControl::__construct()
Set the items list to be empty.
TDropDownList::__construct()
TListBox::__construct()
Sets the HTML tag displaying the listbox.
TPanel::__construct()
TTable::__construct()
Constructor.
TTableCell::__construct()
Constructor.
TTableHeaderCell::__construct()
Constructor.
TTableRow::__construct()
Constructor.
TDataGridItem::__construct()
Constructor.

[ Top ]

method addChild [line 267]

string|null addChild( TComponent $child)

Adds a child component.

The component must have a unique ID among its sibling components, or TComponentIdNotUniqueException will be raised.

If the component does not have an ID, the method will generate one for it.

If the parent component is in a page hierarchy, the child component will be registered to the page recursively.

This method is usually used for dynamically creating components.




return:  the component ID, null if not added
access:  public
see:  registerComponent()


Parameters:

TComponent   $child   the component to be added as a child.

[ Top ]

method addParsedObject [line 214]

void addParsedObject( TComponent|string $object, TComponent $context)

Handles a component or string met in template.

This method will be invoked when a component or a string is parsed by the framework. This method can be overriden to provide customize treatment of parsed objects (e.g., adding the object into the body collection of the component). The default implement will add a component as a child of the template owner ($context) or the container's parent the container is not the template owner.




access:  public


Overridden in child classes as:

TControl::addParsedObject()
Adds the object parsed in template as a body of the component.
TTranslate::addParsedObject()
Adds the object parsed in template as a body of the component.
TContent::addParsedObject()
Override the parent implementation.
TRepeater::addParsedObject()
This method overrides the parent implementation so that no body content is added from template.
TDataGrid::addParsedObject()
This method overrides the parent implementation so that no body content is added from template.
TDataList::addParsedObject()
This method overrides the parent implementation so that no body content is added from template.
TListControl::addParsedObject()
This method overrides the parent implementation to handle TListItem.
TWizard::addParsedObject()
Override the parent implementation.
TWizardTemplate::addParsedObject()
Override the parent implementation.

Parameters:

TComponent|string   $object   the newly parsed object
TComponent   $context   the template owner

[ Top ]

method attachEventHandler [line 512]

void attachEventHandler( string $name, string $handler, [object the $context = null])

Attaches a handler function to an event.

An ID path should be used to refer to a handler method within the context object. By default, the context object is null meaning the context is the component itself. For example, you can use 'Parent.onButtonClick' to refer to the method 'onButtonClick' that is defined in the Parent component.

If the method name doesn't contain any dot and the context object is null, the context will be assumed the Parent of the component. Therefore, 'onButtonClick' is equivalent to 'Parent.onButtonClick'.




access:  public


Parameters:

string   $name   the event name.
string   $handler   the ID path of the method to be attached as an event handler.
object the   $context   context object for the method (default=null)

[ Top ]

method bindProperty [line 752]

void bindProperty( string $name, string $expression)

Sets up the binding between a property and an expression.

The context of the expression is the component itself.




access:  public


Parameters:

string   $name   the property name
string   $expression   the expression

[ Top ]

method canGetProperty [line 657]

boolean canGetProperty( string $name)

Determines whether a property can be read.



access:  public


Parameters:

string   $name   the property name

[ Top ]

method canSetProperty [line 647]

boolean canSetProperty( string $name)

Determines whether a property can be written.



access:  public


Parameters:

string   $name   the property name

[ Top ]

method createComponent [line 911]

TComponent createComponent( string $type, [string $id = ''])

Creates a child component.

This is a convenient function for creating a component and adding it as a child component.




return:  the created component.
access:  public


Parameters:

string   $type   the component type
string   $id   the component ID, empty for implicit ID

[ Top ]

method dataBind [line 879]

void dataBind( [boolean $recursive = true])

Performs the databinding for this component.

Databinding a property includes evaluating the binded expression and setting the property with the evaluation result. This method will invoke TComponent::onDataBinding(). If $recusive is set true, databinding will also be performed for child components recursively.




access:  public


Parameters:

boolean   $recursive   whether to databind child components recursively, default is true.

[ Top ]

method evaluateExpression [line 730]

string evaluateExpression( string $expression)

Evaluates a PHP expression.



return:  the evaluation result
access:  public


Parameters:

string   $expression   PHP expression

[ Top ]

method evaluateStatements [line 707]

string evaluateStatements( string $statements)

Evaluates a list of PHP statements.



return:  content echoed or printed by the PHP statements
access:  public


Parameters:

string   $statements   PHP statements

[ Top ]

method findObject [line 840]

mixed findObject( string $idPath)

Finds an object by its ID path.

For example, if HomePage is the parent of MenuBar which is the parent of UserName, then the UserName component can be located by the ID path "MenuBar.UserName" in HomePage.




return:  the object, null if not found
access:  public


Parameters:

string   $idPath   the ID path of the object to be located

[ Top ]

method getApplication [line 391]

void getApplication( TApplication 0)



access:  public


Parameters:

TApplication   0   the application instance

[ Top ]

method getChild [line 245]

TComponent|null getChild( string $id)



return:  the child component, null if not found
access:  public


Parameters:

string   $id   the child component ID

[ Top ]

method getChildren [line 236]

array getChildren( )



return:  the list of all children
access:  public


[ Top ]

method getDefinition [line 156]

TComponentSpecification getDefinition( [string $type = ''])

Returns or builds a component definition.

This method should only be used by framework developers.




return:  the component definition
static:  
access:  public


Parameters:

string   $type   the component type

[ Top ]

method getGlobalization [line 459]

TGlobalization getGlobalization( )

Returns the Globalization instance for the application.



access:  public


[ Top ]

method getID [line 794]

string getID( )



return:  the component ID
access:  public


[ Top ]

method getModule [line 420]

TModule getModule( )

Returns the module object that contains the component or the page containing the component.

This method is overriden by TPage.




return:  the module object that contains the component or the page containing the component.
access:  public


Overridden in child classes as:

TPage::getModule()
Returns the module object.

[ Top ]

method getPage [line 410]

void getPage( TPage 0)



access:  public


Parameters:

TPage   0   the page object, null if the component is not in a page (maybe in a module).

[ Top ]

method getParent [line 814]

TComponent|null getParent( )



return:  the parent object, null if no parent
access:  public


[ Top ]

method getPropertyInitValue [line 668]

void getPropertyInitValue( string $name)

Gets the initial value of a property.

The assignment will be realized by calling initProperties. This method should only be used by framework developers.




access:  public


Parameters:

string   $name   property name

[ Top ]

method getPropertyType [line 627]

string|null getPropertyType( mixed $name)

Returns the type of a property



return:  the property type, null if property is not defined.
access:  public


[ Top ]

method getRequest [line 450]

TRequest getRequest( )

Returns the request object associated with application.



access:  public


[ Top ]

method getServiceManager [line 468]

TServiceManager getServiceManager( )

Returns the service manager for this application.



access:  public


[ Top ]

method getSession [line 441]

ISession getSession( )

Returns the session object associated with the application.



return:  the session object associated with the application.
access:  public


[ Top ]

method getSessionState [line 925]

mixed getSessionState( string $key)

Returns a session variable.

This function is used to fetch a variable persistent within a user session.




return:  the session variable value, null if no session or the named variable doesn't exist.
access:  public


Parameters:

string   $key   the session variable name

[ Top ]

method getUniqueID [line 827]

string getUniqueID( )

Returns the unique ID of the component.

The unique ID can be used for id attribute or name attribute of a HTML element. Internally, it is used by the framework to identify postback target and post data loaders.




return:  the unique ID for the component
access:  public


[ Top ]

method getUser [line 432]

IUser getUser( )

Returns the user object associated with the application.



return:  the user object associated with the application.
access:  public


[ Top ]

method hasChildren [line 228]

boolean hasChildren( )



return:  whether the component has any child
access:  public


[ Top ]

method hasEvent [line 489]

boolean hasEvent( string $name)

Determines whether an event is defined.



access:  public


Parameters:

string   $name   the event name

[ Top ]

method hasProperty [line 637]

boolean hasProperty( string $name)

Determines whether a property is defined.



access:  public


Parameters:

string   $name   the property name

[ Top ]

method initProperties [line 690]

void initProperties( )

Initializes the property values.

This method should only be used by framework developers.




access:  public


[ Top ]

method instantiateTemplate [line 195]

void instantiateTemplate( string $str)

Parses a template string and instantiates the content.

The method will parse the template string and instantiate the components defined in the template. Components instantiated will be added as children of this component. Components and static text are added as body content of their corresponding container components.




access:  public


Parameters:

string   $str   the template string

[ Top ]

method onDataBinding [line 898]

void onDataBinding( TEventParameter $param)

This method is invoked when dataBind is invoked for the component.

The method raises 'OnDataBinding' event. If you override this method, be sure to call the parent implementation so that the event handlers are invoked.




access:  protected


Overridden in child classes as:

TRepeater::onDataBinding()
Parses and intantiates templates.
TDataGrid::onDataBinding()
Generates the content in the data grid.
TDataList::onDataBinding()
Parses and intantiates templates.
TListControl::onDataBinding()
This method is invoked when OnDataBinding event is raised.

Parameters:

TEventParameter   $param   event parameter to be passed to the event handlers

[ Top ]

method raiseEvent [line 527]

void raiseEvent( string $name, TComponent $sender, TEventParameter $param)

Invokes all attached event handler functions for a particular event.



access:  public


Parameters:

string   $name   the event name
TComponent   $sender   the component that fires the event
TEventParameter   $param   the event parameter

[ Top ]

method removeChild [line 292]

void removeChild( TComponent $child)

Removes a child component.

If the child component is registered in a page hierarchy, it will be unregistered.




access:  public


Parameters:

string   $child   the ID of the child component to be removed

[ Top ]

method removeChildren [line 307]

void removeChildren( )

Removes all child components.

If the child component is registered in a page hierarchy, it will be unregistered.




access:  public


[ Top ]

method setAttribute [line 480]

void setAttribute( string $name, string $value)

Sets an attribute.

The default implementation does nothing. This method is overriden by TControl.




access:  public


Overridden in child classes as:

TControl::setAttribute()
Sets an attribute.

Parameters:

string   $name   the attribute name
string   $value   the attribute value

[ Top ]

method setDefinition [line 171]

void setDefinition( string $type, TComponentSpecification $definition)

Sets a component definition.

This method should only be used by framework developers.




static:  
access:  public


Parameters:

string   $type   the component type
TComponentSpecification   $definition   the component definition

[ Top ]

method setID [line 781]

void setID( string $id)

Sets a component ID.

A component cannot change its ID once it is set, or an exception will be raised. It is recommended that the ID should be set by supplying the ID parameter to the createComponent method of TApplication.




access:  public


Parameters:

string   $id   the component ID

[ Top ]

method setParent [line 806]

void setParent( TComponent $parent)

Sets the parent of this component.

This method should only be used by framework developers. If you want to add a child component, use addChild instead.




access:  public


Parameters:

TComponent   $parent   the parent

[ Top ]

method setPropertyInitValue [line 680]

void setPropertyInitValue( string $name, string $value)

Sets the initial value of a property.

The assignment will be realized by calling initProperties. This method should only be used by framework developers.




access:  public


Parameters:

string   $name   property name
string   $value   property value in string format

[ Top ]

method setRoot [line 402]

void setRoot( TComponent $root)

Sets the root component in the component hierarchy.

The root component can be either a page or a module object. This method should only be used by framework developers.




access:  public


Parameters:

TComponent   $root   the root component

[ Top ]

method setSessionState [line 942]

void setSessionState( string $key, mixed $value)

Sets a session variable.

This function is used to save a variable in session.




access:  public


Parameters:

string   $key   the session variable name
mixed   $value   the session variable value

[ Top ]

method unbindProperty [line 766]

void unbindProperty( string $name)

Breaks the binding between a property and an expression.



access:  public


Parameters:

string   $name   the property name

[ Top ]

method __get [line 574]

mixed __get( string $name)

Returns a property value by name or a child component by ID.

If the child component ID is the same as the property name, the property takes precedence. If none are present, the method raises an exception.

This function is provided so that you can get a property or a component by ID paths, e.g.: $this->MenuBar->HomeLink->Text where Text is the property name of HomeLink which is a child component of MenuBar which is a child component of $this. Since property name takes precedence over component ID, you may need to call getChild if you want to get a child component whose ID is identical to a property name.




return:  the child component or the property value
access:  public


Parameters:

string   $name   the child component ID or the property name

[ Top ]

method __set [line 602]

void __set( string $name, mixed $value)

Sets value of a component property.

The property must be defined in the component specification. Otherwise an exception will be raised.




access:  public


Parameters:

string   $name   the property name
mixed   $value   the property value

[ Top ]


© 2004-2005 PRADO Software Group. All Rights Reserved.