From 05b69a565ebf001f42fdb6558f204bf3f1a9b61a Mon Sep 17 00:00:00 2001 From: xue <> Date: Thu, 4 May 2006 19:57:16 +0000 Subject: Added TCompositeControl. --- demos/quickstart/protected/pages/Controls/NewControl.page | 6 +++--- .../pages/Controls/Samples/LabeledTextBox2/LabeledTextBox.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'demos/quickstart/protected/pages/Controls') diff --git a/demos/quickstart/protected/pages/Controls/NewControl.page b/demos/quickstart/protected/pages/Controls/NewControl.page index 61209b6b..51d0cc02 100644 --- a/demos/quickstart/protected/pages/Controls/NewControl.page +++ b/demos/quickstart/protected/pages/Controls/NewControl.page @@ -13,7 +13,7 @@ In general, there are two ways of writing new controls: composition of existing Composition is the easiest way of creating new controls. It mainly involves instantiating existing controls, configuring them and making them the constituent components. The properties of the constituent components are exposed through subproperties.

-One can compose a new control in two ways. One is to override the TControl::createChildControls() method. The other is to extend TTemplateControl (or its child classes) and write a control template. The latter is easier to use and can organize the layout constituent compoents more intuitively, while the former is more efficient because it does not require parsing of the template. +One can compose a new control in two ways. One is to extend TCompositeControl and override the TControl::createChildControls() method. The other is to extend TTemplateControl (or its child classes) and write a control template. The latter is easier to use and can organize the layout constituent compoents more intuitively, while the former is more efficient because it does not require parsing of the template.

As an example, we show how to create a labeled textbox called LabeledTextBox using the above two approaches. A labeled textbox displays a label besides a textbox. We want reuse the PRADO provided TLabel and TTextBox to accomplish this task. @@ -48,13 +48,13 @@ In the above, the method call to ensureChildControls() ensures that bot

Composition by Overriding createChildControls()

-For a composite control as simple as LabeledTextBox, it is better to create it by extending TControl and overriding the createChildControls() method, because it does not use templates and thus saves template parsing time. Note, the new control class must implement the INamingContainer interface to ensure the global uniqueness of the ID of its constituent controls. +For a composite control as simple as LabeledTextBox, it is better to create it by extending TCompositeControl and overriding the createChildControls() method, because it does not use templates and thus saves template parsing time.

Complete code for LabeledTextBox is shown as follows,

-class LabeledTextBox extends TControl implements INamingContainer { +class LabeledTextBox extends TCompositeControl { private $_label; private $_textbox; protected function createChildControls() { diff --git a/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox2/LabeledTextBox.php b/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox2/LabeledTextBox.php index 4b8ac2c2..5bbf4ce2 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox2/LabeledTextBox.php +++ b/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox2/LabeledTextBox.php @@ -1,6 +1,6 @@