[CLUE-Tech] ASP alternative.
    David Anselmi 
    anselmi at americanisp.net
       
    Wed Dec  3 20:18:14 MST 2003
    
    
  
Dale K. Hawkins wrote:
> David Anselmi <anselmi at americanisp.net> writes:
> 
> 
>>Here's an example.  In ASP, a few lines of code run a database query
>>and a few more hook it into a "datagrid control" (most of that can be
>>done drag and drop but that isn't too important).
> 
> 
> I thought I'd send a follow example of using smarty and
> DB_DataContainer with php.  All very powerful and simple code.
> 
> Is this few enough lines of code?  :-)
> 
> ========== people.php 8< ==========
> 
> require 'Smarty.class.php';
> 
> require_once 'DB.php';
> require_once 'DB/sqlite.php';
> require_once('DB/DataContainer.php');
> 
[...]
 >
> $dbh = &new DB_sqlite();
> $dbh->connect($dsn, array('persistent'=> true) );
> 
> $smarty = new Smarty;
> 
> $smarty->compile_check = true;
> $smarty->debugging = true;
> 
> $params[classname] = 'person';
> $params[limit]     = 10;
> $people = Person::getObjects($dbh, $params);
> 
> $smarty->assign('people', $people);
> 
> $smarty->display('people.tpl');
Yes, this is pretty close to what ASP does.  That's cool that there's no 
html in this file either.  But...
> ========== people.tpl 8< ==========
> 
> {include file="header.tpl" title="Phone Book"}
> 
> <table class="select-list">
>    <tr class="header">
>       <th>Name</th>
>       <th>Number</th>
>    </tr>
> {foreach from=$people item=person}
>    <tr class="{cycle values="odd,even"}">
>       <td class="item"><a href="edit-person.php?tid={$person->id}" {popup text="Edit Entry"}>{$person->lastname}, {$person->firstname}</a></td>
>       <td class="item">{$person->mobile}</td>
>    </tr>
> {/foreach}
> </table>
> 
> <p>
> 
> {include file="footer.tpl"}
This seems like extra work.  In ASP the whole table would be replaced 
with something like:
<asp:DataGrid runat="server" id="myGrid"/>
You could certainly add a bunch to this to get a particular look but by 
default it will show all the columns without having to write code 
knowing how many there are.  I guess that for something really custom it 
isn't too much different.
It's nice to know this can be done in PHP though.  Thanks for the example.
Dave
    
    
More information about the clue-tech
mailing list