From fa51a0a2e3ce4ec4a82a5d2f53fbd50cfcb16528 Mon Sep 17 00:00:00 2001
From: Fabio Bas
We start by editing the Home.page file found in the currency-converter/protected/pages/ directory. Files ending with ".page" are page templates that contains HTML and Prado controls. - We simply add two textboxes, three labels and one button as follows. + We simply add two textboxes, three labels and one button as follows.
If you refresh the page, you should see something similar to the following figure.
It may not look very pretty or orderly, but we shall change that later using CSS.
@@ -125,7 +125,7 @@ php prado/framework/prado-cli.php -c currency-converter
to add a "Home.php" to where "Home.page" is. The Home class
should extends the
Prado uses PHP's __autoload method to load classes. The convention is to use the class name with ".php" extension as filename. @@ -151,15 +150,15 @@ class Home extends TPage the converted total. To handle the user clicking of the "Convert" button we simply add an OnClick property to the "Convert" button in the "Home.page" template and add a corresponding event handler method - in the "Home.php". + in the "Home.php".
+
The value of the OnClick, "convert_clicked", will be the method name in the "Home.php" that will called when the user clicks on the - "Convert" button. + "Convert" button.
If you run the application in your web browser, enter some values and click the "Convert" button then you should see that calculated value displayed next @@ -186,24 +185,24 @@ class Home extends TPage
We shall now examine, the three lines that implements the simply currency - conversion in the "convert_clicked" method. -
+ conversion in the "convert_clicked" method. +The statement $this->currencyRate corresponds to the TTextBox component with ID value "currencyRate" in the "Home.page" template. The Text property of the TTextBox contains the value that the user entered. So, we obtain this value by $this->currencyRate->Text which we convert the - value to a float value. + value to a float value.
The next line does a similar things, it takes the user value from the TTextBox with ID value "dollars and converts it to @@ -212,9 +211,9 @@ $dollars = floatval($this->dollars->Text);
The third line calculates the new amount and set this value in the Text property of the TLabel with ID="total". - Thus, we display the new amount to the user in the label. + Thus, we display the new amount to the user in the label.
-
To ensure 1 we add one
To ensure 1 we just add another TRequiredFieldValidator, for 2
we could use a
The server side logic remains the same, we just need to import the Active Controls name space as they are not included by default. We - add the following line to the begin of "Home.php". + add the following line to the begin of "Home.php".
To indicate that the calculation is in progress, we can change the text of the "total" label as follows. We add a ClientSide.OnLoading property to the "Convert" button (since this button is responsible for requesting - the calculation). + the calculation).
We simply create a CSS file named "common.css" and save it in the themes/Basic directory. Then we add the following code - to the beginning of "Home.page" (we add a little more HTML as well). + to the beginning of "Home.page" (we add a little more HTML as well).
The first line <%@ Theme="Basic" %> defines the theme to be used for this page. The -- cgit v1.2.3