For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > June 2004 > Smarty Loops and DataObject Formbuilder









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Smarty Loops and DataObject Formbuilder
Verona Busch

2004-06-26, 8:56 am

Hi,

I would like to output my tables through DB_DataObject_FormBuilder into
an smarty.tpl. Cause DataObject creates my classes automaticly, I don't
want to set every column label and every row into the templatefile by
myself, of cource. But how do I have to build in the loops in smarty
template?


index2.php
------------------------------------------------------------
<?php
include('Smarty.class.php');

// Create the template object
$smarty =& new Smarty;
$smarty->template_dir = '.';
$smarty->compile_dir = '.\tmp';

// Create the renderer object
$renderer =& new HTML_QuickForm_Renderer_ArraySmarty($sma
rty);

// build the HTML for the form
$form->accept($renderer);

// assign array with form data
$smarty->assign('form_data', $renderer->toArray());

// parse and display the template
$smarty->display('index.tpl');

?>
------------------------------------------------------------



index2.tpl
------------------------------------------------------------
<table>
{section name=mysec loop=$renderer}
{strip}
<tr bgcolor="{cycle values="#aaaaaa,#bbbbbb"}">
<td>{$renderer[mysec].field_1}</td> |
<td>{$renderer[mysec].field_2}</td> | <-- loop in here?
<td>{$renderer[mysec].field_3}</td> |
</tr>
<tr bgcolor="{cycle values="#aaaaaa,#bbbbbb"}">
<td>{$renderer[mysec].field_a}</td> |
<td>{$renderer[mysec].field_b}</td> | <-- loop in here?
<td>{$renderer[mysec].field_c}</td> |
</tr>
{/strip}
{/section}
</table>
------------------------------------------------------------



output2
------------------------------------------------------------
<table>
<tr bgcolor="#aaaaaa"><td>1</td><td>2</td><td>3</td></tr>
<tr bgcolor="#bbbbbb"><td>a</td><td>b</td><td>c</td></tr>
....
</table>
-------------------------------------------------------------


If I use this template, I get a table with Arrays:

index2_b.tpl
------------------------------------------------------------
<form {$form_data.attributes}>
<!-- Display the fields -->
<table>
<tr>

{foreach from=$form_data item=item}

<td>{$item}</td>

{/foreach}

</tr>
</table>
</form>
------------------------------------------------------------

Thanks Vero
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com