Smarty db

From PeacockWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 05:40, 30 August 2005 (edit)
Trevorp (Talk | contribs)

← Previous diff
Revision as of 06:14, 30 August 2005 (edit)
Trevorp (Talk | contribs)

Next diff →
Line 37: Line 37:
==TODO== ==TODO==
# caching # caching
 +# smarty html plugins
 +# smarty sql plugins
 +# php coding
 +# generator queries
 +# manual table queries
 +# manual field queries

Revision as of 06:14, 30 August 2005

Introduction

Smarty_DB is a php object model written by Trevor peacock for use with the TimeShare project. Smarty_DB generates an object model of a database (currently only MySQL is supported). Smarty_DB uses the Smarty Templating Engine for rendering SQL commands, and also provides plugins to smarty for use in normal HTML templates, allowing many database queries to be done directly from smarty templates with no PHP code required.

Principles

Smarty makes a few assumptions about your database

  1. Wherever one table references another table, the foreign key field will have the same name as the foreign table, and the foreign key field will have the value of the key in the foreign table, where the key is the field 'id'.
 +-----------+
 | author    |
 +-----------+
 | id        |
 | name      |
 | dob       |
 |           |
 +-----------+

 +-----------+
 | book      |
 +-----------+
 | id        |
 | name      |
 | pub_date  |
 | author    |
 |           |
 +-----------+

This example follows rule #1. The author field in the book table is a pointer to the id of the author table. This allows Smarty_DB to recognise the link, and automatically allow the programmer to simply reference the foreign table.

//$book is a Smarty_DB object containing a single book object.
$author = $book->author;

In this example Smarty_DB recognises the link between book and author, and automatically runs a SQL query to fetch the data related to the author, and returns it as a Smarty_DB object. This can be quite a powerful mechanism for performing lookups

print "Book Title: ".$book->name 
print "Author: ".$book->author->name;

TODO

  1. caching
  2. smarty html plugins
  3. smarty sql plugins
  4. php coding
  5. generator queries
  6. manual table queries
  7. manual field queries
Personal tools