Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<com:TContent ID="body" >
2
<h1 id="401">My First PRADO Application</h1>
3
<div id="hello1"  class="block-content">
4
<p id="50034">
5
In this section, we guide you through creating your first PRADO application, the famous "Hello World" application.
6
</p>
7
<p id="50035">
8
"Hello World" perhaps is the simplest <i>interactive</i> PRADO application that you can create. It displays to end-users a page with a submit button whose caption is <tt>Click Me</tt>. After the user clicks on the button, its caption is changed to <tt>Hello World</tt>.
9
</p>
10
<p id="50036">
11
There are many approaches that can achieve the above goal. One can submit the page to the server, examine the POST variable, and generate a new page with the button caption updated. Or one can simply use JavaScript to update the button caption upon its <tt>onclick</tt> client event.
12
</p>
13
</div>
14
<p id="50037" class="block-content">
15
PRADO promotes component-based and event-driven Web programming. The button is represented by a <tt>TButton</tt> object. It encapsulates the button caption as the <tt>Text</tt> property and associates the user button click action with a server-side <tt>OnClick</tt> event. To respond to the user clicking on the button, one simply needs to attach a function to the button's <tt>OnClick</tt> event. Within the function, the button's <tt>Text</tt> property is modified as "Hello World". The following diagram shows the above sequence,
16
<img src="<%~sequence.gif%>" class="figure"/>
17
</p>
18
<p id="50038" class="block-content">
19
Our PRADO application consists of three files, <tt>index.php</tt>, <tt>Home.page</tt> and <tt>Home.php</tt>, which are organized as follows,
20
<img src="<%~directory.gif%>" class="figure"/>
21
 
22
where each directory is explained as follows. Note, the above directory structure can be customized. For example, one can move the <tt>protected</tt> directory out of Web directories. You will know how to do this after you go through this tutorial.
23
</p>
24
<ul id="dir-struct" class="block-content">
25
<li><tt>assets</tt> - directory storing published private files. See <a href="?page=Advanced.Assets">assets</a> section for more details. This directory must be writable by the Web server process.</li>
26
<li><tt>protected</tt> - application base path storing application data and private script files. This directory should be configured as inaccessible to end-users.</li>
27
<li><tt>runtime</tt> - application runtime storage path storing application runtime information, such as application state, cached data, etc. This directory must be writable by the Web server process.</li>
28
<li><tt>pages</tt> - base path storing all PRADO pages.</li>
29
</ul>
30
 
31
<div class="tip">
32
<b class="tip">Tip:</b>You may also use the <tt>framework/prado-cli.php</tt>
33
<a href="?page=GettingStarted.CommandLine">command line script</a>
34
to create the Prado project directory structure. For example, type the command
35
<tt>php path/to/prado-cli.php -c helloworld</tt> in the directory
36
where you want to create the <tt>helloworld</tt> project.
37
</div>
38
 
39
<p id="50040">
40
The three files that we need are explained as follows.
41
</p>
42
<ul id="file-list" class="block-content">
43
<li><tt>index.php</tt> - entry script of the PRADO application. This file is required by all PRADO applications and is the only script file that is directly accessible by end-users. Content in <tt>index.php</tt> mainly consists of the following three lines,
44
<com:TTextHighlighter CssClass="source block-content" id="code_50003">
45
require_once('path/to/prado.php');  // include the prado script
46
$application=new TApplication;      // create a PRADO application instance
47
$application->run();                // run the application
48
</com:TTextHighlighter>
49
</li>
50
<li><tt>Home.page</tt> - template for the default page returned when users do not explicitly specify the page requested. A template specifies the presentational layout of components. In this example, we use two components, <tt>TForm</tt> and <tt>TButton</tt>, which correspond to the &lt;form&gt; and &lt;input&gt; HTML tags, respectively. The template contains the following content,
51
<com:TTextHighlighter Language="prado" CssClass="source block-content" id="code_50004">
52
<html>
53
  <body>
54
    &lt;com:TForm&gt;
55
      &lt;com:TButton Text="Click me" OnClick="buttonClicked" /&gt;
56
    &lt;/com:TForm&gt;
57
  </body>
58
</html>
59
</com:TTextHighlighter>
60
</li>
61
<li><tt>Home.php</tt> - page class for the <tt>Home</tt> page. It mainly contains the method responding to the <tt>OnClick</tt> event of the button.
62
<com:TTextHighlighter CssClass="source block-content" id="code_50005">
63
class Home extends TPage
64
{
65
    public function buttonClicked($sender,$param)
66
    {
67
        // $sender refers to the button component
68
        $sender->Text="Hello World!";
69
    }
70
}
71
</com:TTextHighlighter>
72
</li>
73
</ul>
74
<div id="hello-end" class="block-content">
75
<p id="50041">
76
The application is now ready and can be accessed via: <tt>http://Web-server-address/helloworld/index.php</tt>, assuming <tt>helloworld</tt> is directly under the Web <tt>DocumentRoot</tt>. Try to change <tt>TButton</tt> in <tt>Home.page</tt> to <tt>TLinkButton</tt> and see what happens.
77
</p>
78
<p id="50042">
79
Complete source code of this demo can be found in the PRADO release. You can also try the <a href="http://www.pradosoft.com/demos/helloworld/">online demo</a>.
80
</p>
81
</div>
82
 
83
<div class="last-modified">$Id: HelloWorld.page 1650 2007-01-24 06:55:32Z wei $</div></com:TContent>