Here is what I was thinking. A nice UML diagram would be best but I can't figure out ArgoUML right now.
DrLivingstone and others feel free to nitpick 
PHP Code:
/**
* VO object holding article information
* Pass an array to constructor
*/
class Article
{}
/**
* VO object holding category information
* Pass an array to constructor
*/
class Category
{}
/**
* Iterator pattern implementation
* Contains methods for manipulating a list
* e.g. current(), num_rows(), rewind()
*/
class Iterator
{}
/**
* Base mapper class
* Contains abstract methods for object relational mapping
* e.g. write(), update(), delete()
* perhaps contains a database abstraction object for querying
*/
class Mapper
{}
/**
* Specific mapper class for an article
* Contains SQL for object relational mapping
* implements abstract methods in Mapper
*/
class ArticleMapper extends Mapper
{}
/**
* Specific mapper class for a category
*/
class CategoryMapper extends Mapper
{}
/**
* Article validation
* Contains a few methods for validating a new article
* isValid() returns true if validation passed
*/
class ArticleValidator
{}
/**
* Factory class
* for object creation
*/
class Factory
{}
// article.php
$cat_id = isset( $_REQUEST['cat'] ) ? $_REQUEST['cat'] : null;
$art_id = isset( $_REQUEST['id'] ) ? $_REQUEST['id'] : null;
$mapper = new ArticleMapper;
// Discover what the request is
if( $art_id )
{
$resource = $mapper->findById( $art_id );
}
elseif( $cat_id )
{
$resource = $mapper->findByCategory( $cat_id );
}
else
{
// some default action
}
// Load the resource in the iterator
$iterator = new Iterator( $resource );
// Display
if( $iterator->num_rows() > 0 )
{
while( $article = Factory::makeArticle( $iterator->current() ))
{
echo $article->getTitle();
echo $article->getBody();
}
}
// add_article.php
if( isset( $_POST['submit'] ))
{
// Build an article object from POST
$article = Factory::makeArticle( $_POST );
$validator = new ArticleValidator( $article );
// write the new article if it's valid
if( $validator->isValid() )
{
$mapper = new ArticleMapper;
if( $mapper->write( $article ))
{
// Redirect somewhere
}
else
{
// Some error occurred
}
}
}
// Display an HTML form
Bookmarks