Reply to Re: [SMARTY] Dynamic Variables

Your name:

Reply:


Posted by Jochem Maas on 10/02/75 11:17

Stephen J. Lawrence Jr. wrote:
> Well, I have 12 different sets of variables on this page that I display
> in a form. The html is all identical except for the variable names. I am
> trying to keep from having to hardcode 12 different HTML TR's for each
> of the vars.
>
> On the PHP side, I have done this:
> $this->digits =
> array('1','2','3','4','5','6','7','8','9','0','aa','bb','cc');
> foreach($this->digits as $digit)
> {
> $type_varname = 'page_key_' . $digit. '_type';
> $this->{$type_varname} = $rs->fields['page_key_' . $digit .
> '_type'];
> }
>
> Then I want a foreach in the template to spin through each of the
> variables.
>
> {foreach from=digits item=$digit}
> <input name="page_key_{$digit}_value"

why not {$page_obj->getPageKeyValue($DIGIT)}
where the following method is defined in your object:

function getPageKeyValue($d)
{
if (!in_array($d, $this->digits) return null;
return $page_obj->{"page_key_$d_value"};
}

obviously untested, hth.

> value="{$page_obj->page_key_$DIGIT_value}" size="10" />
> {/foreach}
>
> the "name=page_key_{$digit}_value" part works fine, but the "value="
> part does not. The first loopthrough, the value needs to be
> $page_obj->page_key_1_value, the second through needs to be
> $page_obj->page_key_2_value, etc..
>
> steve
>
> Bill Cunningham wrote:
>
>> Stephen,
>>
>> That was a much clearer explaination of what you're looking
>> for.
>>
>> It appears that perhaps you want an array there. Something
>> like:
>>
>> $my_obj->var[$cnt] ??
>>
>> What about:
>> $var = "variable_1_value";
>>
>> $my_obj->$$var ?? <<- not sure if a variable indirection
>> works in a template though.
>>
>>
>> Maybe it would help if you told us exactly why you are
>> trying to achieve this. Are you trying to auto create a
>> bunch of templates?
>>
>>
>> - Bill
>>
>>
>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация