|
You are here: Home / Documentation / Dynamic Object-Generation with saf.Database.Generic |
Dynamic Object-Generation with saf.Database.GenericA Complete ExampleLet's create a simple product area for our web site. This small app will contain the following boxes:
First, there's the category list for the sidebar: boxes/categories/index.php
<?php
loader_import ('myapp.Objects');
$category = new Category;
if ($box['context'] == 'action') {
page_title ('Categories');
}
echo template_simple ('categories.spt', $category->find (array ()));
?>
html/categories.spt
<ul>
{loop obj}
<li><a href="/index/myapp-category-action/category.{loop/id}"
>{loop/name}</a>
</li>
{end loop}
</ul>
Next up is the list of products for each category: boxes/category/index.php
<?php
loader_import ('myapp.Objects');
$category = new Category ($parameters['category']);
page_title ('Category: ' . $category->val ('name'));
echo template_simple ('category.spt', $category->getProducts ());
?>
html/category.spt
{loop obj}
<h2>
<a href="/index/myapp-product-action/product.{loop/id}">{loop/name}</a>
</h2>
<p>${loop/price}</p>
<p>
{loop/description}
<a href="/index/myapp-product-action/product.{loop/id}">More Info</a>
</p>
{end loop}
<p>
<a href="/index/myapp-app">Back</a>
</p>
And finally we have the individual product detail screen: boxes/product/index.php
<?php
loader_import ('myapp.Objects');
$product = new Product ($parameters['product']);
page_title ($product->val ('name'));
echo template_simple ('product.spt', $product->makeObj ());
?>
html/product.spt
<p>${price}</p>
<p>{description}</p>
<p>
<a href="/index/myapp-category-action/category.{category}">Back</a>
</p>
As a final touch, let's make our app's default handler the 'categories' box, so that visitors start where they ought to automatically. Add the following to the inc/app/myapp/conf/config.ini.php file: default_handler = categories default_handler_type = box Now you should be able to see your application in action at the following address: http://www.example.com/index/myapp-app Page 1: Introduction to Generic |
|
Copyright © 2008, SIMIAN systems Inc. All rights reserved. Privacy policy Some of the icons on this site were created by the Gnome Project. |