2006-12-08 03:39:06 Code for the Links page
Here's the code that went into the links page, as used in the current state of this php system. It consists of the .php controller, the .html template file, and the .css style sheet, thusly:

( php )
  1  <?php
2 include( '.Controller.php' );
3
4 class Control extends Controller {
5
6 function __construct() {
7 parent::__construct();
8 $this->log( 'new WebPage', 'HyperJeff Blog Lynks of Olde' );
9 $page = new WebPage( 'HyperJeff Blog Lynks of Olde' );
10 $links = new Table( 'links', 'blog' );
11
12 foreach( $links->each() as $link ) {
13 $dateParts = split( ' ', $link['created'] );
14 $page->setMultipleFieldsForTemplate( 'links', array(
15 'linkDate' => $dateParts[0], // ex: "2006-12-07"
16 'linkTitle' => $link['title'],
17 'linkURL' => $link['url'],
18 'linkComment' => $link['comment'],
19 'linkCommentSpot' => ($link['comment'] ? '' : ' '),
20 ));
21 }
22 print $page->fullPage();
23 }
24 }
25 new Control();
26 ?>

The Table object automatically makes available all fields of the table, so things like 'title' and 'url' for the link are just read off the fields in the table "links" in the database "blog". The $this->log line is for the logging system, the output of which is shown at the bottom.

( html )
  1  <div class="blog">
2 <div id="links">
3 <div id="linksTitle">Lynks of Olde:</div>
4 <ul>
5 <field: links>
6 <li>
7 <span class="comment">
8 <field: linkDate /> &mdash;
9 </span>
10 <a href="" /><field: linkTitle /></a>
11 <field: linkCommentSpot>
12 <span class="comment">&mdash; <field: linkComment /></span>
13 </field: linkCommentSpot>
14 </li>
15 </field: links>
16 </ul>
17 </div>
18 </div>

The template allows the controller to suck in everything between <field: links> and <\field: links> and iteratively populate the subfields and then replace the block with the resulting sum.

( css )
  1  #links                { font-family:Verdana; padding:10px; margin:10px 10px 0 10px; }
2 #links a { font-size:0.9em; }
3 #linksTitle { font-size:1.5em; text-align:center; text-shadow:3px 3px 3px #aaa; }
4 #links ul { margin:10px 15px; list-style:none; }
5 #links li { margin-top:5px; padding:3px; }
6 #links li:hover { background:white; border:1px solid #A0ABBF; padding:2px; }
7 .comment { color:black; font-family:papyrus; }


Here's what the logging looks like when the page loads, fwiw:
  1  Object created: WebPage < Page < Object (Object id #2)
2 Object lifespan: 0.152646 seconds
3
4 Object created: Table < Database < Object (Object id #3)
5 Database, Table: blog, links
6 Object lifespan: 0.155429 seconds
7
8 Object created: Control < Controller < Object (Object id #1)
9 Host: blog.hyperjeff.net
10 Script: /links.php
11 Request method: GET
12 User Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/521.25 (KHTML, like Gecko) Safari/521.24
13 Referrer: http://blog.hyperjeff.net/
14 new WebPage: HyperJeff Blog Lynks of Olde
15 Object lifespan: 0.163702 seconds

(with the exception that in a Terminal window, the coloring makes it look much nicer)
Leave a comment