Components

A component is an instance of TComponent or its child class. The base class TComponent implements the mechanism of component properties and events.

Component Properties

A component property can be viewed as a public variable describing a specific aspect of the component, such as the background color, the font size, etc. A property is defined by the existence of a getter and/or a setter method in the component class. For example, in TControl, we have

class TControl extends TComponent {
    public function getID() {
        ...
    }
    public function setID($value) {
        ...
    }
}
This defines a property named ID. Reading the property (e.g. echo $component->ID;) is equivalent to invoking the getter method (e.g. echo $component->getID();); and writing the property (e.g. $component->ID='Button';) is equivalent to invoking the setter method (e.g. $component->setID('Button');).

A property is read-only if it has a getter method but no setter method. Since PHP method names are case-insensitive, property names are also case-insensitive. A component class inherits all its ancestor classes' properties.

Component Events

Component events are special properties that take method names as their values. Attaching (setting) a method to an event will hook up the method to the places at which the event is raised. Therefore, the behavior of a component can be modified in a way that may not be foreseen during the development of the component.

A component event is defined by the existence of an on-method. For example, in TButton, we have

class TButton extends TWebControl {
    public function onClick($param) {
        ...
    }
}
This defines an event named Click, and a handler can be attached to the event using one of the following ways,
$button->Click=$callback;
$button->Click->add($callback);
$button->Click[]=$callback;
$button->attachEventHandler('Click',$callback);
where $callback refers to a valid PHP callback (e.g. a function name, a class method array($object,'method'), etc.)

Component Instantiation

Component instantiation means creating instances of component classes. There are two types of component instantation: static instantiation and dynamic instantiation. The created components are called static components and dynamic components, respectively.

Dynamic Component Instantiation

Dynamic component instantiation means creating component instances in PHP code. It is the same as the commonly referred object creation in PHP. A component can be dynamically created using one of the following two methods in PHP,

$component = new ComponentClassName;
$component = Prado::createComponent('ComponentType');
where ComponentType refers to a class name or a dot-connected type name (e.g. System.Web.UI.TControl). The second approach is introduced to compensate for the lack of namespace support in PHP.

Static Component Instantiation

Static component instantiation is about creating components via configurations. The actual creation work is done by the PRADO framework. For example, in an application configuration, one can configure a module to be loaded when the application runs. The module is thus a static component created by the framework. Static component instantiation is more commonly used in templates. Every component tag in a template specifies a component that will be automatically created by the framework when the template is loaded. For example, in a page template, the following tag will lead to the creation of a TButton component on the page,

<com:TButton Text="Register" />