PradoSoft

Creating your first PRADO application

From PRADO Wiki

In this tutorial, we guide you through creating your first PRADO application, the famous "Hello World" application.

"Hello World" perhaps is the simplest interactive PRADO application that you can create. It displays to end-users a page with a button whose caption is "Click Me". After the user clicks on the button, the caption is changed to "Hello World".

In PRADO, the button is represented by a TButton object which represents the button caption using a property called Text. When the button is clicked, a server-side event called OnClick will be raised. We can respond to this event and set the button caption to "Hello World". The following diagram shows the above sequence,

Image:HelloworldSequence.gif

Much of the complexity as you see in the above diagram have been done by the PRADO framework. As a developer, you only need to write the piece of code to set the Text property.

We will need three files for our PRADO application: index.php, Home.page and Home.php. They are organized in the following directory structure. Detailed explanation to this organization can be found in the quickstart tutorial.

Image:HelloworldDirectory.gif

  • index.php - 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 index.php mainly consists of the following three lines,
 
<?php
require_once('path/to/prado.php');  // include the prado script
$application=new TApplication;      // create a PRADO application instance
$application->run();                // run the application 
?>
  • Home.page - 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, TForm and TButton, which correspond to the <form> and <input> HTML tags, respectively. The template contains the following content,
 
<html>
  <body>
    <com:TForm>
      <com:TButton Text="Click me" OnClick="buttonClicked" />
    </com:TForm>
  </body>
</html>
  • Home.php - page class for the Home page. It mainly contains the method responding to the OnClick event of the button.
 
<?php
class Home extends TPage
{
    public function buttonClicked($sender,$param)
    {
        // $sender refers to the button component
        $sender->Text="Hello World!";
    }
}
?>

The application is now ready and can be accessed via URL http://hostname/path/to/helloworld/index.php. Try to change TButton in Home.page to TLinkButton and see what happens.

Personal tools
Your user name:

Your password:

MediaWiki