AMO Framework

Standard

Most of the template and db framework is in place for AMO v2.0. I struggled a bit with how to relate Smarty and PEAR::DB objects to the rest of the modules. After a lot of tinkering, I ended up deciding to not instantiate new ones with every module, but rather use global instances of these objects and pass them by reference in the constructors of each module.

The drawback? Not as pretty. The reason? Speed and scalability. As it stands, the framework behaves like this:

  1. Define config variables.
  2. Instantiate Smarty object.
  3. Instantiate PEAR::DB wrapper class.
  4. Attempt to connect to database, display “gone fishing” page on failure.
  5. Filter inputs into $clean array (if any).
  6. Populate $sql array with properly escaped values for use in queries (if any).
  7. Query for data using global $db object.
  8. Pass all necessary data to Smarty via assign().
  9. Disconnect and destroy $db, display page output.

With some more poking around, I was able to use auto prepend/append to group all init and finish items into one file. As a result, each PHP document was successfully limited to the following steps:

  1. Filter inputs into $clean array (if any).
  2. Populate $sql array with properly escaped values for use in queries (if any).
  3. Query for data using global $db object.
  4. Pass all necessary data to Smarty via assign().

See an example of this at work.

Pending updates to the main template, we could be moving straight into reworking the developers area by next week. That will present some added twists, like session handling, RDF parsing and complex items like the review queue — but it’ll be fun.

Until then, the oh-so-important public side of AMO will improve one piece at a time by hammering on this framework.

The smallest deed outweights the greatest of intentions.