1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
<com:TContent ID="body" >
<h1>Components</h1>
<p>
A component is an instance of <code>TComponent</code> or its child class. The base class <code>TComponent</code> implements the mechanism of component properties and events.
</p>
<h2>Component Properties</h2>
<p>
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 <code>TControl</code>, we have
<pre class="source">
class TControl extends TComponent {
public function getID() {
...
}
public function setID($value) {
...
}
}
</pre>
This defines a property named <code>ID</code>. Reading the property (e.g. <code>echo $component->ID;</code>) is equivalent to invoking the getter method (e.g. <code>echo $component->getID();</code>); and writing the property (e.g. <code>$component->ID='Button';</code>) is equivalent to invoking the setter method (e.g. <code>$component->setID('Button');</code>).
</p>
<p>
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.
</p>
<h2>Component Events</h2>
<p>
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.
</p>
<p>
A component event is defined by the existence of an <code>on</code>-method. For example, in <code>TButton</code>, we have
<pre class="source">
class TButton extends TWebControl {
public function onClick($param) {
...
}
}
</pre>
This defines an event named <code>Click</code>, and a handler can be attached to the event using one of the following ways,
<pre class="source">
$button->Click=$callback;
$button->Click->add($callback);
$button->Click[]=$callback;
$button->attachEventHandler('Click',$callback);
</pre>
where <code>$callback</code> refers to a valid PHP callback (e.g. a function name, a class method <code>array($object,'method')</code>, etc.)
</p>
<h2>Component Instantiation</h2>
<p>
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.
</p>
<h3>Dynamic Component Instantiation</h3>
<p>
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,
<pre class="source">
$component = new ComponentClassName;
$component = Prado::createComponent('ComponentType');
</pre>
where <code>ComponentType</code> refers to a class name or a dot-connected type name (e.g. <code>System.Web.UI.TControl</code>). The second approach is introduced to compensate for the lack of namespace support in PHP.
</p>
<h3>Static Component Instantiation</h3>
<p>
Static component instantiation is about creating components via <a href="?page=Configurations.Overview">configurations</a>. The actual creation work is done by the PRADO framework. For example, in an <a href="?page=Configurations.AppConfig">application configuration</a>, 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 <a href="?page=Configurations.Templates1">templates</a>. 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 <code>TButton</code> component on the page,
<pre class="source">
<com:TButton Text="Register" />
</pre>
</p>
</com:TContent>
|