Re: Re: Smarty + QuickForm
| From: | Verona Busch | Date: | Fri, 25 Jun 2004 23:41:06 +0000 |
| Subject: | Re: Re: Smarty + QuickForm | ||
| References: | 1 2 3 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-13348@lists.php.net to get a copy of this message | ||
Hi,
maybe you can help me too? I think I mixed up with to many packages, but I'm not sure.
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].field3}</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>
-------------------------------------------------------------
This here I found in some tutorial:
index.php
------------------------------------------------------------
<?php
include('Smarty.class.php');
// create object
$smarty = new Smarty;
// assign an array of data
$smarty->assign('name', array('bob','jim','joe','jerry','fred'));
// assign an associative array of data
$smarty->assign('users', array(
array('name' => 'bob', 'phone' => '555-3425'),
array('name' => 'jim', 'phone' => '555-4364'),
array('name' => 'joe', 'phone' => '555-3422'),
array('name' => 'jerry', 'phone' => '555-4973'),
array('name' => 'fred', 'phone' => '555-3235')
));
// display it
$smarty->display('index.tpl');
?>
------------------------------------------------------------
index.tpl
------------------------------------------------------------
<table>
{section name=mysec loop=$name}
{strip}
<tr bgcolor="{cycle values="#eeeeee,#dddddd"}">
<td>{$name[mysec]}</td>
</tr>
{/strip}
{/section}
</table>
<table>
{section name=mysec loop=$users}
{strip}
<tr bgcolor="{cycle values="#aaaaaa,#bbbbbb"}">
<td>{$users[mysec].name}</td>
<td>{$users[mysec].phone}</td>
</tr>
{/strip}
{/section}
</table>
------------------------------------------------------------
output
------------------------------------------------------------
<table>
<tr bgcolor="#eeeeee"><td>bob</td></tr>
<tr bgcolor="#dddddd"><td>jim</td></tr>
<tr bgcolor="#eeeeee"><td>joe</td></tr>
<tr bgcolor="#dddddd"><td>jerry</td></tr>
<tr bgcolor="#eeeeee"><td>fred</td></tr>
</table>
<table>
<tr bgcolor="#aaaaaa"><td>bob</td><td>555-3425</td></tr>
<tr bgcolor="#bbbbbb"><td>jim</td><td>555-4364</td></tr>
<tr bgcolor="#aaaaaa"><td>joe</td><td>555-3422</td></tr>
<tr bgcolor="#bbbbbb"><td>jerry</td><td>555-4973</td></tr>
<tr bgcolor="#aaaaaa"><td>fred</td><td>555-3235</td></tr>
</table>
------------------------------------------------------------
Thanks Vero