Building an AJAX Chat Application

This tutorial introduces the Prado web application framework's ActiveRecord and Active Controls to build a Chat web application. It is assumed that you are familiar with PHP and you have access to a web server that is able to serve PHP5 scripts. This basic chat application will utilize the following ideas/components in Prado.

In this tutorial you will build an AJAX Chat web application that allows multiple users to communicate through their web browser. The application consists of two pages: a login page that asks the user to enter their nickname and the main application chat page. You can try the application locally or at Pradosoft.com. The main application chat page is shown bellow. class="figure" />

Download, Install and Create a New Application

The download and installation steps are similar to those in the Currency converter tutorial. To create the application, we run from the command line the following. See the Command Line Tool for more details. php prado/framework/prado-cli.php -c chat

The above command creates the necessary directory structure and minimal files (including "index.php" and "Home.page") to run a Prado web application. Now you can point your browser's URL to the web server to serve up the index.php script in the chat directory. You should see the message "Welcome to Prado!"

Authentication and Authorization

The first task for this application is to ensure that each user of the chat application is assigned with a unique (chosen by the user) username. To achieve this, we can secure the main chat application page to deny access to anonymous users. First, let us create the Login page with the following code. We save the Login.php and Login.page in the chat/protected/pages/ directory (there should be a Home.page file created by the command line tool).

<?php class Login extends TPage { } ?> Prado Chat Demo Login <com:TForm>

Prado Chat Demo Login