PHP development Tool-prado 1.6 Introduction and Installation

Source: Internet
Author: User
Tags define contains copy error code html page html tags php code php programming
Ado

Introduction to the 1th Chapter

  1.1 what is Prado?

Prado is an event-driven and component-based Web application Development framework in the PHP5 environment. Using Prado to develop Web applications, the main thing you need to do is to use the existing components (the original is "instantiated already defined components", familiar with object-oriented programming developers may be easier to understand this sentence), set the properties of the component, for the control component of the various events to write the corresponding processing functions, Then organize them into a page. (Translator note: The individual tends to translate component into components, control translates into controls, in fact, most occasions are not different, but in order to make it easier for readers to understand the original text, this article will be translated according to this rule.) This process is very similar to developing a Windows application using RAD development tools such as Delphi or Visual Basic.

The following is a simple example to illustrate the workings of the Prado framework. Suppose we now want to use Prado to develop a common login page. First we select the 2 ttextbox controls in Prado and a TButton control to correspond to the user name input, the password input and the submit button respectively. The TextMode property of the Ttextbox control entered by the corresponding password is then set to "Password" and a handler function is specified for the OnClick event of the TButton control login. Finally put these controls in the appropriate place on the page template (which will explain what the page template is, in fact, it is similar to an HTML page), a full-featured login page is implemented. The control handles how to display the data, how to get the data entered by the user, how to respond to the user's actions, and so on. For example, thettextbox control displays an input box for the user to enter; The password entered by the user is displayed as the * number, and the developer can read the Text of the Ttextbox control by reading the code property to get the password that the user actually entered, and thelogin function will be invoked automatically when the user clicks on the Submit button. This is very different from the traditional PHP programming approach. Using traditional PHP programming, developers need to use HTML tags to display user input boxes and buttons, and they need to parse post data to get user input and determine if the button is clicked, and so on.

PRADO

Component-based programming makes code reuse extremely convenient. Some repetitive monotonous work such as form input validation, page state management can be handled using Prado already provided components. Developers can also meet requirements by inheriting existing components or by combining existing components to develop new components. Other new components are about to be released.

In general, PRADO provides the following benefits for programmers in PHP:

    • Reusability-code that conforms to the Prado component standard is highly reusable.
    • Easy to use-using the Prado component is very simple, usually you just need to configure their properties and write the relevant event handler functions.
    • Robustness-Prado lets developers stop being bothered by the annoying code that has many bugs. Its code is composed of objects, methods, and properties, not URL addresses and various query parameters. PHP5 's latest exception processing mechanism has also been introduced, allowing developers to pinpoint the number of lines of error code.
    • Efficient-Prado development of Web applications is running fast. Prado implements a caching mechanism that uses the operational efficiencies of its developed applications to match the operational efficiencies of applications developed by the commonly used template engine.
    • Teamwork-Prado allows separation of content and presentation. components, especially pages, keep content (logic) and presentation in separate files.

There are already a lot of PHP frameworks, Mojavi, Wact, PHP. MVC, Phrame and so on. They are primarily a set of loosely organized PHP code (such as Model-view-controller). Some of them are more geared toward developing a content management system and providing more functionality such as user management modules.

Compared with these frameworks, Prado is more focused on building a code reuse and event-driven programming standard. If you've ever developed a Windows program with these RAD tools such as Delphi or Visual Basic, you'll find that using Prado to develop web apps is very similar, and you can quickly master Prado for Web application development. In most cases, all you have to do is set up the component's properties and the response component's events. A higher level of code reuse, such as the user Management module described earlier, can be implemented based on the Prado component.

Prado thought first I was thinking from the Apache Tapestry project. At the time of design and implementation, Borland Delphi and Microsoft ASP. NET's design thought has played the very important role. In fact, people who have used asp.net can find that there are many places in Prado that are similar to them.

1.2 installation


The Prado requires a PHP5 environment, as well as a simplexml module (the module is already included in the default installed environment PHP5). In Windows XP and Redhat Linux environments, tests have been passed on both Apache and IIS Web servers.

The Prado framework is published using a. zip file. You can use unzip under Linux, and you can use WinZip to decompress under Windows. After the decompression is complete, a directory Prado is created in the current directory. This directory mainly includes the following files and directories:

Readme.html            documentation for this project
The contents of index.html and readme.html are the same.
copyright information for this project
HISTORY Version Upgrade information
core code for framework/Prado framework
Some examples of examples/Prado
docs/ Prado's Help document

When you are done understanding the pressure, copy everything from the Prado directory to the root of the Web server. (You can also copy it to a subdirectory, or even a deeper directory, Prado there is no limit to this.) If you copy it to a subdirectory, the following URL address needs to be modified accordingly. )

Very simple, the installation is complete! Now you can try the three examples in the Prado release package: ' Hello, world! ', The Hangman Game (a guessing game), and the Prado address Book, their URL addresses are:

    • "Hello, world!"- http://<Web-server-address>/examples/helloworld.php
    • The Hangman game- http://<Web-server-address>/examples/hangman.php
    • The PRADO phonebook- http://<Web-server-address>/examples/phonebook.php

1.3 Example: Hello, world!

In this section, we mainly explain ' Hello, world! '

This example gives you an impression of using Prado development. This example is very simple, there is only one page, which shows a button "click me". When the user clicks on the button, the caption of the button becomes ' Hello, world! '.

These files are required to complete this function,

    • helloworld.php , application of the main entrance;
    • Helloworld/application.spec, application of the configuration file;
    • helloworld/homepage.php, pages of the class file;
    • Helloworld/homepage.tpl, the template file for the page.

Note that the directory HelloWorld should be set to not be accessible to web users (nor can read permissions) because the files include important data information (such as the connection password for the database, and so on). Don't worry about setting up Web users will not be able to access the normal, because in fact they do not have to access the HelloWorld directory files. You should do the same in other applications that use Prado development.

In the helloworld.php file, the program is primarily an instantiation of the Tapplication class, which you can understand if you don't understand the word instantiation. is to declare a variable of type tapplication. and start running the application with the following code:

<?php require_once ('.. /framework/tapplication.php ');
$app =tapplication::getinstance (' Helloworld/application.spec ');
$app->run ();
?>

Here we assume that the code for the framework is located in the . The/framework directory.

Each Prado application should have such an entry file. The main difference between them is getinstance
The parameter of the function, which indicates the location of the applied configuration file.

Application.spec is an XML file that is used to configure parameters at the application level. (Just as a global variable, of course, is now read-only, we are deciding whether to allow read-write in the next release) in this case, it contains the following code:

<?xml version= "1.0" encoding= "UTF-8"?>
<application default-page= "homepage" cache-path= "" >
<alias name= "Pages" path= "."/>
<using namespace= "System.Web.UI.WebControls"/>
<using namespace= "Pages"/>
</application>

<alias> Element (Translator Note:,<alias>...</alias> the whole translation as an element by the usual translation of an XML file, where alias is translated as an element label, The values in a pair of closed alias tags are translated to element values, name, path these are translated as attribute names, their values are translated into property values, reference "< Label property name = attribute value > element value </label >") define the path alias. The alias system is defined internally by the systems to indicate the directory in which the framework's core code resides. You can use path aliases to define namespaces. A namespace is actually a directory that is added to the PHP search path include_path . <using> element indicates the namespace used by the startup application. (You can also call the Using () function in your code to use a single namespace)

the <application> default-page property indicates which page is entered by default when the application starts. Here we specify the homepage page, which corresponds to a page class homepage (specifically for the page and page classes that are explained later).

The homepage.tpl file is a page class homepage A template file that contains the following code:

<title>hello, world!</title>
<body>
<com:TForm>
<com:tbutton text= "Click Me" />
</com:TForm>
</body>

It's very similar to HTML pages. The only difference is the element <com:TButton> , which represents a
TButton components. The TButton component will appear as a button for a form, with the button titled "Click Me", "click
Me is specified in the Text property. By setting onclick , you can specify the page method ClickMe to respond to the button's OnClick event. Therefore, when the button is clicked, the method ClickMe is automatically invoked.

The homepage.php file contains code that defines the page class homepage , as follows:

<?php
Class Homepage extends Tpage
{
function ClickMe ($sender, $param)
{
$sender->text= "Hello, world!";
}
}
?>

The homepage class inherits the Tpage class. The Tpage class is provided by the Prado framework itself, which is the base class for all page classes. The homepage class contains only one method ClickMe , which is the method that responds to the button OnClick event in the page template we mentioned just now ClickMe . The purpose of this method's code is to set the Text property of the event's sender $sender (here is this button) as ' Hello, world! '. We expect that when the user clicks the button, the button's caption is changed to ' Hello, world! '.
This example, contained in the PRADO release package, can be visited via this URL:href= "http:// /examples/helloworld.php" >http://<web-server-address >/examples/helloworld.php
.
You might say what a fuss it is to accomplish such a simple function. Yes, this feature is really very simple, with a few lines of PHP code can be done. But the main purpose of this example is to get you to feel the Prado programming approach, which is object-oriented, component-based, and event-based driven. More complex features can be implemented in a similar way, please continue with the following chapters.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.