Smarty Loops and DataObject Formbuilder

From: Date: Sat, 26 Jun 2004 09:15:34 +0000
Subject: Smarty Loops and DataObject Formbuilder
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-13353@lists.php.net to get a copy of this message
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($smarty);
    // 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

« previous php.pear.general (#13353) next »