PHP开发利器-PRADO 1.6入门与安装
ado
第1章 入门
1.1 PRADO是什么?
PRADO是在PHP5环境下的一个基于事件驱动和基于组件的WEB应用开发框架。使用PRADO开发WEB应用,你主要需要做的工作就是使用已有的组件(原文是"实例化已经定义好的组件",熟悉面向对象编程的开发者可能比较容易理解这句话),设置组件的属性,为控件组件的各种事件编写对应的处理函数,然后把这些组织成一个个的页面。(译者注:个人倾向于将component翻译为组件,control翻译为控件,事实上大多数场合两者没有什么区别,但是为了读者能够更加容易理解原文,本文一律按此规则翻译。)这个过程和使用RAD开发工具(比如Delphi或者Visual Basic)来开发Windows应用程序非常类似。
下面用一个简单的例子来说明PRADO框架的工作原理。假定我们现在要使用PRADO来开发一个常见的登录页面。首先我们选择PRADO中的2个TTextBox控件和1个TButton控件来分别对应用户名输入,密码输入和提交按钮。然后把对应密码输入的TTextBox控件的TextMode属性设置为"Password",并为TButton控件的OnClick事件指定一个处理函数login。最后把这些控件放到页面模板的合适的位置上(后面会解释什么是页面模板,实际上它和一个html页面很相似),一个功能完善的登录页面就实现了。控件会自己处理好如何显示数据,如何得到用户输入的数据,如何响应用户的操作等这些事情。例如,TTextBox控件会显示一个输入框让用户输入;用户输入的密码会被显示为*号,而开发者在代码中可以通过读取TTextBox控件的Text属性来获取用户实际输入的密码;当用户点击了提交按钮的时候,login 函数将会被自动调用。这和传统的PHP编程处理方式很不一样。使用传统的PHP编程方式,开发人员需要使用HTML标签来显示用户输入框和按钮,同时需要自己解析POST数据来获得用户的输入以及判断按钮是否被点击了等等这些事情。
PRADO
基于组件的编程方式使代码的重用极为方便。一些重复性的单调的工作比如表单输入的验证,页面状态的管理等都可以使用PRADO已经提供的组件来处理。开发者也可以通过继承现有的组件或者组合现有的组件来开发新的组件满足要求。另外一些新的组件即将发布。
总来的说,PRADO 为PHP的编程人员提供了以下的有益之处:
- 可重用性 - 符合PRADO组件标准的代码是高度可重用的。
- 易于使用 - 使用PRADO组件非常简单,通常只需要配置它们的属性,编写相关的事件处理函数。
- 健壮性 - PRADO让开发者不再被那些令人厌烦的有很多错误的的代码所困扰。它的代码都是有对象,方法和属性组成的;而不是Url地址和各种query参数。PHP5最新的Exception处理机制也被引入进来,让开发人员能够精确定位到错误代码的所在行数。
- 高效 - PRADO开发的Web应用运行很快。PRADO实现了一种缓存机制,使用其开发的应用的运行效率能够和那些通常使用的模版引擎开发的应用的运行效率相媲美。
- 团队协作 - PRADO允许内容和表现方式分离。组件,尤其是页面,将内容(逻辑)和表现方式分别保存在不同的文件中。
目前已经有很多PHP的框架,Mojavi, WACT , PHP.MVC, Phrame等等。它们主要是建立一套松散的PHP代码组织方式(比如 Model-view-controller)。其中一些更多的面向开发一个内容管理系统,并提供了诸如用户管理模块等更多的功能。
和这些框架相比,PRADO更专注于建立一个代码重用和事件驱动的编程标准。如果你曾经用Delphi或者Visual Basic等这些RAD开发工具来开发Windows程序的话,那么你会发现使用PRADO来开发WEB应用是非常类似的,你可以很快就掌握PRADO来进行WEB应用的开发。大多数情况下,你要做的仅仅是设置组件的属性和响应组件的事件。更高层次的代码重用,比如前面所说的用户管理模块,可以基于PRADO组件来实现。
PRADO的思想最先我是从Apache Tapestry项目想到的。在设计和实现的时候, Borland Delphi 和Microsoft ASP.NET的设计思想起到了很重要的作用 。实际上,使用过ASP.NET的人可以发现PRADO中有很多地方和它是相似的。
1.2 安装
PRADO需要PHP5的环境,以及SimpleXML模块(PHP5缺省安装后的环境下已经包括了这个模块)。在Windows XP和RedHat Linux环境下,已经在Apache和IIS Web服务器上都通过了测试。
PRADO框架使用一个.zip文件发布。在Linux下可以使用unzip,在Windows下可以使用Winzip来解压。解压完毕后,会在当前目录下创建一个目录prado。这个目录主要包括以下这些文件和目录:
README.html 此项目的说明文件<br> index.html 和README.html中的内容是一样的<br> COPYRIGHT 此项目的版权信息<br> HISTORY 版本升级信息<br> framework/ PRADO框架的核心代码<br> examples/ PRADO的一些例子<br> docs/ PRADO的帮助文档
完成了解压之后,把prado目录的所有东西复制到Web服务器的根目录下。(也可以把它复制到某一个子目录下,甚至更深层次的目录下,PRADO对此没有限制。如果你将它复制到了某一个子目录下,以下的URL地址需要做相应的修改。)
非常简单,安装已经完成了!现在你可以试一下PRADO发布包中的三个例子了:``Hello, world!", the Hangman Game(一个猜单词的游戏), 和PRADO通讯录,它们的URL地址是:
- ``Hello, world!" - http://
/examples/helloworld.php - the Hangman game - http://
/examples/hangman.php -
the PRADO phonebook - http://
/examples/phonebook.php
1.3 范例: Hello, World!
在这一节中,我们主要来说明``Hello, world!''
这个例子,让你对使用PRADO开发有一个印象。这个例子非常的简单,只有一个页面,上面显示了一个"Click me"的按钮。当用户点击了这个按钮,这个按钮的标题会变成``Hello, world!''。
要完成这个功能需要这些文件,
- helloworld.php , 应用的主入口;
- helloworld/application.spec, 应用的配置文件;
- helloworld/HomePage.php, 页面的类文件;
- helloworld/HomePage.tpl, 页面的模板文件.
注意,目录 helloworld 应该设置为Web用户不可以访问的(读的权限也不能给),因为其中的文件包括了一些重要的数据信息(比如数据库的连接口令等等)。不用担心这么设置Web用户会不能正常的访问,因为实际上他们根本不用去访问helloworld 目录中的文件。在其它使用PRADO开发的应用中你也应该这么做。
在helloworld.php 文件中,程序主要是实例化 TApplication 这个类,(译者注:如果对实例化这个词不怎么理解,你也可以这么理解,就是申明一个类型为TApplication的变量。)并开始运行应用,代码如下:
<?php require_once('../framework/TApplication.php');<br/> $app=TApplication::getInstance('helloworld/application.spec');<br> $app->run();<br> ?>
这里我们假定框架的代码位于 ../framework 目录下。
每一个 PRADO应用都应该有这么一个入口文件。他们之间主要的区别在于 getInstance
函数的参数的不同,这个参数指明了应用的配置文件的位置。
application.spec 是一个XML文件,用来配置应用级别的参数。(就好象全局变量一样,当然现在是只读的,我们正在决定是否下一版本中允许可读写的)在这个例子中,它包含了如下的代码:
<?xml version="1.0" encoding="UTF-8"?><br/> <application default-page="HomePage" cache-path=""><br/> <alias name="Pages" path="." /><br/> <using namespace="System.Web.UI.WebControls" /><br/> <using namespace="Pages" /><br/> </application><br/>
HomePage.tpl 文件是页面类HomePage一个模板文件,包含如下的代码:
<html><br/> <head><br/> <title>Hello, world!</title><br/> </head><br/> <body><br/> <com:TForm><br/> <com:TButton Text="Click me" /><br/> </com:TForm><br/> </body><br/> </html><br/>
它和HTML页面非常的相似。唯一不同的地方就是元素
TButton 组件。 TButton 组件将会显示为一个表单的按钮,按钮的标题是"Click Me","Click
Me"是在 Text 属性中被指定的。通过设置 OnClick ,可以指定页面方法 clickMe 来响应按钮的 OnClick 事件。因此,当按钮被点击的时候,方法 clickMe 就会被自动调用了。
HomePage.php 文件包含了定义页面类 HomePage 的代码,如下:
<?php<br/> class HomePage extends TPage<br/> {<br/> function clickMe($sender,$param)<br/> {<br/> $sender->Text="Hello, world!";<br/> }<br/> }<br/> ?><br/>
HomePage 类继承了 TPage 类。TPage 类是PRADO框架本身提供的,它是所有页面类的基类。HomePage 类只包含了一个方法clickMe ,这个方法就是刚才我们提到的页面模板中响应按钮OnClick 事件的方法clickMe 。这个方法的代码的作用是设置事件的发送者$sender(这里就是这个按钮)的Text 属性为 ``Hello, world!"。我们期望当用户点击这个按钮的时候,按钮的标题改为``Hello, world!" 。
这个包含在 PRADO 发布包中的例子可以通过此URL来访问:href="http://
.
你可能会说完成这么一个简单的功能有什么大惊小怪的。是的,这个功能确实非常简单,用几行php代码就可以完成。但是这个例子主要是目的是为了让你感受一下PRADO编程方式,它是面向对象的,基于组件和基于事件驱动的。用类似的编程方式可以实现更复杂的功能,请继续看下面几章。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

Windows 11 brings fresh and elegant design to the forefront; the modern interface allows you to personalize and change the finest details, such as window borders. In this guide, we'll discuss step-by-step instructions to help you create an environment that reflects your style in the Windows operating system. How to change window border settings? Press + to open the Settings app. WindowsI go to Personalization and click Color Settings. Color Change Window Borders Settings Window 11" Width="643" Height="500" > Find the Show accent color on title bar and window borders option, and toggle the switch next to it. To display accent colors on the Start menu and taskbar To display the theme color on the Start menu and taskbar, turn on Show theme on the Start menu and taskbar

By default, the title bar color on Windows 11 depends on the dark/light theme you choose. However, you can change it to any color you want. In this guide, we'll discuss step-by-step instructions for three ways to change it and personalize your desktop experience to make it visually appealing. Is it possible to change the title bar color of active and inactive windows? Yes, you can change the title bar color of active windows using the Settings app, or you can change the title bar color of inactive windows using Registry Editor. To learn these steps, go to the next section. How to change title bar color in Windows 11? 1. Using the Settings app press + to open the settings window. WindowsI go to "Personalization" and then

Do you see "A problem occurred" along with the "OOBELANGUAGE" statement on the Windows Installer page? The installation of Windows sometimes stops due to such errors. OOBE means out-of-the-box experience. As the error message indicates, this is an issue related to OOBE language selection. There is nothing to worry about, you can solve this problem with nifty registry editing from the OOBE screen itself. Quick Fix – 1. Click the “Retry” button at the bottom of the OOBE app. This will continue the process without further hiccups. 2. Use the power button to force shut down the system. After the system restarts, OOBE should continue. 3. Disconnect the system from the Internet. Complete all aspects of OOBE in offline mode

Taskbar thumbnails can be fun, but they can also be distracting or annoying. Considering how often you hover over this area, you may have inadvertently closed important windows a few times. Another disadvantage is that it uses more system resources, so if you've been looking for a way to be more resource efficient, we'll show you how to disable it. However, if your hardware specs can handle it and you like the preview, you can enable it. How to enable taskbar thumbnail preview in Windows 11? 1. Using the Settings app tap the key and click Settings. Windows click System and select About. Click Advanced system settings. Navigate to the Advanced tab and select Settings under Performance. Select "Visual Effects"

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

We all have different preferences when it comes to display scaling on Windows 11. Some people like big icons, some like small icons. However, we all agree that having the right scaling is important. Poor font scaling or over-scaling of images can be a real productivity killer when working, so you need to know how to customize it to get the most out of your system's capabilities. Advantages of Custom Zoom: This is a useful feature for people who have difficulty reading text on the screen. It helps you see more on the screen at one time. You can create custom extension profiles that apply only to certain monitors and applications. Can help improve the performance of low-end hardware. It gives you more control over what's on your screen. How to use Windows 11

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible
