The Holy Grail of PHP
Thought I'd share this with the community. I'll be writing a real walkthrough soon, as this combo is too good to keep to myself.
Would love to hear any comments, criticisms, or alternatives. If anyone is interested in helping write a few pages on the topic, send me an email or something too.
What do you get when you combine an automated database object abstraction layer, an embedded templating engine, and an AJAX library?
Unparalled rapid modular development fusing the web's hottest technologies.
And it's easy.
PEAR DB_DataObject
PHP Smarty
xajax
What's it look like? Here's a teenie example.
index.php
ajax.php
template.php
tpl/note.tpl
data.php
schema.sql
Would love to hear any comments, criticisms, or alternatives. If anyone is interested in helping write a few pages on the topic, send me an email or something too.
What do you get when you combine an automated database object abstraction layer, an embedded templating engine, and an AJAX library?
Unparalled rapid modular development fusing the web's hottest technologies.
And it's easy.
PEAR DB_DataObject
PHP Smarty
xajax
What's it look like? Here's a teenie example.
index.php
<?php
require_once 'ajax.php';
?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<?php $xajax->printJavascript(); ?>
<title>Test</title>
</head>
<body>
<form id="frmNote">
<div><b>ID</b>: <input type="text" name="id" id="id" /></div>
<div><input type="button"
onclick="xajax_getNote(xajax.getFormValues('frmNote'))"
value="Get Note" /></div>
</form>
<div id="content"></div>
</body>
</html>ajax.php
<?php
require_once 'xajax/xajax.inc.php';
require_once 'template.php';
function getNote($form) {
$id = $form['id'];
$v = new View();
$objResponse = new xajaxResponse();
$objResponse->addAssign("content","innerHTML", $v->getNote($id));
return $objResponse->getXML();
}
$xajax = new xajax();
$xajax->registerFunction("getNote");
$xajax->processRequests();
?>template.php
<?php
require_once 'Smarty/Smarty.class.php';
require_once 'data.php';
class View extends Smarty {
function View() {
parent::Smarty();
$this->template_dir = 'tpl/';
$this->compile_dir = 'tpl/comp';
$this->config_dir = 'tpl/conf';
$this->cache_dir = 'tpl/cache';
}
function getNote($id = null) {
$note = DB_DataObject::Factory('notes');
$note->get($id);
$this->assign('note', $note);
return $this->fetch('note.tpl');
}
}
?>tpl/note.tpl
<table>
<tr>
<td>{$note->name}</td>
</tr>
<tr>
<td>{$note->body}</td>
</tr>
</table>data.php
<?php
require_once 'PEAR.php';
require_once 'DB/DataObject.php';
//Initialize configuration
$options = &PEAR::getStaticProperty('DB_DataObject','options');
$config = parse_ini_file('do.ini',TRUE);
$options = $config['DB_DataObject'];
?>schema.sql
CREATE DATABASE organizer;
USE organizer;
CREATE TABLE notes (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(32),
body TEXT,
PRIMARY KEY(id)
);