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)
);
August 9 2005, 14:51:19 UTC 6 years ago
August 9 2005, 14:58:29 UTC 6 years ago
What problem were you having? The whole point of the first code block was that you could get a feel for how simple the code ends up looking before committing to reading it all.
August 9 2005, 15:08:23 UTC 6 years ago
Back on topic, though: Thanks. I'll take a look at this tonight.
August 11 2008, 18:53:55 UTC 3 years ago
Anonymous
February 4 2006, 09:32:39 UTC 6 years ago
August 11 2008, 16:53:52 UTC 3 years ago
August 11 2008, 17:15:13 UTC 3 years ago
August 9 2005, 14:59:42 UTC 6 years ago
August 9 2005, 15:13:03 UTC 6 years ago
August 9 2005, 15:31:21 UTC 6 years ago
Besides, AJAX would allow the MVC model to be implemented on the web in a manner that simplifies the user's experience, just as it should've first been.
Ruby-on-Rails is exploding because of its native support for this sort of development, and it seems therefore an appropriate time to discuss and test implementations of similar frameworks for PHP.
August 9 2005, 15:56:12 UTC 6 years ago
What may be an interesting way to support your claim to this combination would be for you to implement a webapp your way and also in another framework as a comparison of ease of use.
A couple of the newer ones that I've found.
PHP on Trax
Biscuit
Jaws
Cake
August 10 2005, 22:39:26 UTC 6 years ago
excellent post, you've always got the goods, i gotta get my hands dirty w/some of this stuff
August 11 2008, 12:15:52 UTC 3 years ago
August 12 2005, 00:23:56 UTC 6 years ago
August 12 2005, 01:03:07 UTC 6 years ago
PEAR::DB has better design and a more active community.
In all honesty, I think PHP 5.5/6.0 is going to introduce a real contender in PDO. Keep your eyes on that, and if you've got a development machine handy, I'd suggest grabbing a build from snaps.php.net and getting your hands wet with PDO.
Anonymous
September 1 2005, 23:13:22 UTC 6 years ago
ADODB Vs Pear::DB Vs PDO
I use ADODB extensivly and find its great. Especially you can npw use it as a PHP extension... but, its clunky and not very lightweight. Pear::DB is slightly slower and not as nice in some areas, but great in others (Select meu generation is a great feature in ADODB, but also limited). To be honest I can't wait to try PDO, its looking really good and should be very fast. Just my useless 2c worth :) Great post by the way.Anonymous
November 22 2005, 03:49:46 UTC 6 years ago
xajax
Hi Michael. This is the xajax project owner. Thanks so much for your interesting article. We're glad that you have found xajax to be useful. I thought I would let you know that we have been working hard on a new release of xajax. We plan to release a beta of the upcoming release later this week. Some of the new features include:* New error handling: Non-fatal PHP errors can now be easily trapped and written to a log file or displayed in an alert dialog in the client.
* OOP: You can now register instance and static class methods to be callable through xajax. This is essential to make it easy to add xajax to many OOP CMS solutions.
* Internationalization: xajax defaults to use UTF-8, but we've added the ability to set the charset to whatever you need to.
* External Function Registration: you can now register functions in external .php files and xajax will dynamically include the file and call the function only if it is requested.
We will soon be setting up at xajaxproject.org, but for now you can visit our forums at:
http://www.intuitivefuture.com/xajaxforu
I am interested in your feedback and your needs as you work with xajax. Feel free to ask questions and make feature requests. Thanks,
J. Max Wilson
xajax project owner
Anonymous
January 28 2006, 14:25:55 UTC 6 years ago
Mutreta das grossas...
Cara, isso ai é engembração, mutreta das grossa. hahahaAnonymous
June 12 2006, 16:25:19 UTC 5 years ago
what should be in do.ini?
what should be write in do.ini? I got following message:Warning: parse_ini_file(): Cannot open 'do.ini' for reading in d:\appserv\www\html\live\data.php on
Anonymous
June 13 2006, 08:23:58 UTC 5 years ago
Re: what should be in do.ini?
a quite stupid question I asked... since I never used dataobject @@for someone who has the same question as me.
[DB_DataObject]
database = mysql://xxx:xxxx@localhost/xxxx
schema_location = classes
class_location = classes
require_prefix = /dataobjects/
class_prefix = DataObjects_
Anonymous
July 6 2006, 02:22:45 UTC 5 years ago
undefined function: get()
Thank you for your nice combination of scripts.I am currently got a problem when I click GetNote button. It shows an error msg as below,
------------------------------------
Error: the XML response that was returned from the server is invalid.
Received:
Fatal error: Call to undefined function: get() in d:\appserv\www\live\template.php on line
16
You have whitespace in your response.
------------------------------------
line 16 is $note->get($id);
Any idea and suggestion are appreciated.
Anonymous
October 27 2006, 14:02:34 UTC 5 years ago
Alternative to DB:DataObject
Personally I live by phpobjectgenerator.com -- look at their tutorials for how to use it!Anonymous
December 9 2010, 08:22:34 UTC 1 year ago