Smarty db
From PeacockWiki
(diff) ←Older revision | Current revision | Newer revision→ (diff)
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
- 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
- caching
- smarty html plugins
- smarty sql plugins
- php coding
- generator queries
- manual table queries
- manual field queries