Home > Archive > PHP Pear > June 2004 > Re: [PEAR] Re: Smarty + QuickForm
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 |
Re: [PEAR] Re: Smarty + QuickForm
|
|
| Sarah Gray 2004-06-25, 6:46 pm |
| Hi,
I'm currently using formBuilder and QuickForm with Smarty (I think I
initiated a post about this a while back). I found those below examples to
be good tutorials just by reading the comments and adapting the code. It was
relatively straightforward to adapt the material to my needs. Basically, you
pass the form to the renderer and then loop through and layout the array in
smarty like any other array. I don't know how much I could help, but if you
have any questions I am happy to share my experiences.
s.
Thomas Schulz wrote:
> Don Fitzsimmons wrote in php.pear.general:
>
>
> Have a lock at:
>
> [PEAR-Path]/docs/HTML_QuickForm/docs/renderers/SmartyStatic_example.php
> [PEAR-Path]/docs/HTML_QuickForm/docs/renderers/SmartyDynamic_example.php
>
> ThS.
>
> --
> PEAR General Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
| |
| Verona Busch 2004-06-25, 7:42 pm |
| 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($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].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
| |
| Thomas Schulz 2004-06-26, 8:56 am |
| Verona Busch wrote in php.pear.general:
> 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?
[PEAR-Path]/docs/HTML_QuickForm/docs/renderers/SmartyDynamic_example.php
[PEAR-Path]/docs/HTML_QuickForm/docs/renderers/templates/smarty-dynamic.tpl
This Example uses the Array-Renderer and does exactly what you like.
ThS.
|
|
|
|
|