PHPBuilder - Value Objects and Data Access Objects with PHP 4.2.x Page 7



RSS Twitter
Articles Databases

Value Objects and Data Access Objects with PHP 4.2.x - Page 7

by: Geno Timlin
|
June 1, 2004

In appedit.php we display a form loaded with the vehicle data. The form POSTs to the appupdate.php script.

<?php
$id 
$_GET["id"];
$dao = new VehicleDAO();
$vo $dao->findByPK($id);
...
    <
input type="text" name="year" value="<?=$vo->year?>" />
    <
input type="text" name="model" value="<?=$vo->model?>" />
    <
input type="text" name="color" value="<?=$vo->color?>" />
...
?>
In appupdate.php, we create an empty VehicleVO object and read in the data from the form. The VO is then passed to the update() method of a VehicleDAO object.

<?php

$vo 
= new VehicleVO();
$dao = new VehicleDAO();
$vo->readForm();
$records_updated $dao->update($vo);
...
?>
Summary
Now this is NOT the pure Model/View/Controller design that J2EE developers are all drooling over these days, but it's close enough for horseshoes. I am sure that with PHP 5 deeper object oriented capabilities, a better MVC design will arise. But I believe this is a pretty good object oriented design for now.
Also, I've included a PHP page that builds the VO and DAO classes for you. How much easier can you get it?
Geno Timlin

« Previous Page
1
|
2
|
3
|
4
|
5
|
6
|
7

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Geno Timlin

Comment:



Comment:

(Maximum characters: 1200). You have characters left.