PHP-WAX Development Framework

PHP-WAX is a lightweight PHP framework built using the Model, View, Control (MVC) architecture. It allows rapid development through abstraction of common tasks such as database connections, validations and session handling. The framework has been optimised for use in a collaborative environment with the inclusion of tools for database migration, a plugin architecture and a standard deployment process.  PHP-WAX also includes features to simplify the inclusion of AJAX functionality.

Quick Example

As a quick example I’ll demonstrate what is required to display a single record from a database once the PHP-WAX framework and a skeleton application has been installed.

For this example we’ll assume that a database has been created with a table named ‘product’ and the fields of ‘id’,’title’,’desc’.

We’ll need to create/modify three files, a controller, model and a view. A folder view of the default skeleton application is shown below.

app
   - config
   - controller
   - db
      - migrate
   - lib
   - model
   - test
   - view

Model

The model is used to read/write persistent data stored outside the application instance such as database or file content.

Create a new file named Product.php in the model dir. By simply extending the WXActiveRecord class using the table name ‘Product’ the model will provide access to the database defined in config.yml and table named ‘product’. This allows us to retrieve and write data to the ‘product’ table.

class Product extends WXActiveRecord {}

Controller

A controller implements the logic of the application; no data or visual elements are stored in the controller.

Create a new public method named ‘product’ in PageController.php, this will become available via the url ‘/product’.  To pick out a specific record in the database simply initialise a ‘Product’ model passing the id of the product in the database. To make the product variable accessible to the view we need to specify it as a public class attribute.

public function product(){
   $this->product = new Product(1);
}

View

The view is used to output content to a device, in this example XHTML.

The filename of the view file should correspond with the controller method, in this example ‘product.html’. To access the fields in the model specify the database field as a class attribute.

echo $product->title

More from this section

RECENT PERSONAL WORK

AllTradeArt Case Study
Kwik Travel Case Study
Allotment Case Study
Revolutionshirts Case Study

RECENT ARTICLES

Import Error: No module named django.core.management

Installing and testing the Django Framework on my new mac I came acro... read more

Quick Note on Setting Up a Mail Server

Part of the basics when setting up a mail server but I needed to put ... read more

Microformats Creator Tool

"Microformats are a way of adding simple markup to human-readable... read more

Recursive Directory Listing

Nothing too fancy but a nice way of viewing a directory tree on your ... read more

CREDITS

powered by php-wax the php framework