PHP-WAX Development Framework
Published: 2007-05-12
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
RECENT ARTICLES
Lightweight blog created on Ruby/GAA/Datastore stack
Put this together a month or two back but never got around to replaci... read more
Using Node JS and Couch DB Stack for Web Dev
With the recent hype surrounding Node.js I thought I'd better get my ... read more
Campaign Monitor API Using PHP and SOAP
Campaign Monitor has a fairly comprehensive API and support docs.&nbs... read more
Google Maps Snippet
Absolute bare basics when it comes the Google Map api but a snippet o... read more