Get your PHP on the right Trax
Hands on Ruby on Rails has become a popular framework for developing database-based web applications using the Model-View-Controller (MVC) pattern.
Before Ruby on Rails, though, PHP was hogging the web-development limelight. Problem was, there was no Model-View-Controller (MVC) framework for PHP.
With Ruby on Rails, though, PHP developers have come to realize the timesaving benefits of MVC - a fact that led to the development of various PHP frameworks that are actually based on Ruby on Rails.
Among them, the Akelos framework and PHP On Trax.
In this article we shall develop an MVC Create-Read-Update-Delete (CRUD) application using the PHP On Trax Framework. Why this particular framework? Simple: it is a direct port of the Ruby on Rails framework.
Install PHP On Trax
Install Apache HTTP Server 2.2 in
C:/Apache directory and PHP 5.2 in
C:/PHP directory, and configure the Apache server with PHP. Install a MySQL 5.0/6.0 database and enable the MySQL extension in the
php.ini configuration file. by removing the ';' from the following line:
extension_dir directive in
php.ini to the directory containing the extensions.
extension_dir = "./ext"
Set error reporting in
php.ini file to
error_reporting = E_ERROR
We also need to install the MDB2 driver for MySQL, which is available as a PHP Extension and Application Repository (PEAR) module. First, install PEAR if not already installed. Download go-pear.php and run the following command to install PEAR:
Download the MDB2 driver for MySQL Copy the .tar file to the
C:/PHP directory. Install the MDB2 driver with the following command:
C:/PHP>pear install -o MDB2_Driver_mysql-1.4.1.tar
PHP On Trax is available as a PEAR module. Run the following commands to install PHP On Trax:
>pear channel-discover pear.phpontrax.com >pear install trax/PHPonTrax
A PHP on Trax directory gets created in the
C:\PHP\PEAR directory. Create a
trax.bat file in the
C:/PHP directory, which is in the
PATH environment variable. To the
trax.bat file add the following code:
php C:\PHP\PEAR\PHPonTrax\trax.php %1
.phtml type to the
httpd.conf file to render the
.phtml view templates.
AddType application/x-httpd-php .php .phtml
.phtml view templates contain a short form of PHP's open tags. Enable the short open tags in
short_open_tag = On
Start your build
In this section we create a PHP on Trax application. The MVC application shall be used to create, read, update and delete catalog entries in a database table. Create an application catalog in the Apache web server root using trax.bat with the following command:
C:\Apache\htdocs >trax catalog
A trax application with an application structure similar to a Ruby on Rails application gets created. The
app directory consists of the
controllers directory for the controller PHP scripts, the
models directory for the model scripts and the
views directory for the view templates.
Wheres the 3rd generation rails?
My problem with these CRUDy things is they are all so naive. After years of writing DB's I practically never access it unless thru procedures that almost never access one table alone.
All you need is a few clever naming trix and a matching form handling library and you can knock a front end up via the DB itself - and move the DB to any provider changing a connection string.
@annoying - if you'd used MVC you may have stayed coding
What we're finding is that using Zend framework and Smarty based MVC means that the code is kind of folding in on itself and getting easier and easier.
Say we are producing a bespoke solution. I.e. there is no existing web app like SQL-Ledger, RT, Twiki, Moodle etc etc etc which fulfils the requirements.
OK - So we're going to build a web based application - after all - coders have changed from 4GL, VB, Delphi, to web based like a herd of wildebeest thundering over the plain.
Let's get the framework in place - by which I mean the DEV/TEST/LIVE LAMP servers, backups logins for developers, Twiki page etc, etc.
Now we put in place a basic MVC based app.
Once we are up and running the development gets easier and easier - we just concetrate on getting the clients specs correct - and building a DB structure which will be able to hold the data.
Actually implementing the interface (using Smarty) becomes very easy.
It's difficult to fully explain - but it feels as if after all the different ways of implementing PHP based applications and everybody re-inventing the wheels we are finally closing in on a standard.
I also like Code Igniter.
I'd rather have these examples on a UNIX platform though: there's something so retarded about c:\php as an installation directory.