[nycphp-talk] JSON and MVC
Daniel Convissor
danielc at analysisandsolutions.com
Sat Jul 18 10:40:30 EDT 2009
Hey Hans:
In a prior engagement, we were using XUL as the view and JSON as the
communication protocol. This was nice, since the entire user interface
resided on the user's desktop (as a Firefox Add-on), all we needed to
transmit was the data. Of course, you need to be using HTML, so
transpose the XUL I'm showing here into HTML. The framework we created
used a consistent naming scheme, so the names of elements in the XUL
matched identifiers in the database.
This is a quick example. There's a lot more code and abstraction
involved, of course.
-----------------
<tree id="tree_loan" onselect="select_loan_tree_item(this)"
ondblclick="select_loan(this.currentIndex)">
<treecols>
<treecol id="loan_id" label="Loan Id" />
<splitter class="tree-splitter"/>
<treecol id="borrower_last_name" label="Borrower" />
<splitter class="tree-splitter"/>
<treecol id="borrower_borrower_ssn" label="Borrower SSN" />
</treecols>
<treechildren />
</tree>
-----------------
<?php
$sql = 'SELECT loan_id, borrower_last_name, borrower_borrower_ssn
FROM loan';
$result = <execute $sql>;
$out = array();
foreach ($result as $row) {
$out[$row['loan_id']] = $row;
}
echo json_encode($out);
-----------------
FYI, in XUL, a "tree" is an element that is used in situations where you
need to automatically repeat the structure for each row to form a
list/table like output. Pretty sweet.
--Dan
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
data intensive web and database programming
http://www.AnalysisAndSolutions.com/
4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409
More information about the talk
mailing list