Re: [SMARTY] Problems with appending values to an array
| From: | Monte Ohrt | Date: | Wed, 19 Feb 2003 16:40:23 +0000 |
| Subject: | Re: [SMARTY] Problems with appending values to an array | ||
| References: | 1 2 3 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-7901@lists.php.net to get a copy of this message | ||
here here!
committed.
Monte
On Wed, 2003-02-19 at 10:17, messju mohr wrote:
> On Wed, Feb 19, 2003 at 05:06:53PM +0100, Joscha Feth wrote:
> > > Von: messju mohr [mailto:messju@lammfellpuschen.de]
> > > you can only apppend one value at a time, i guess.
> > > and you cannot supply your own keys, i'm afraid.
> > >
> > > maybe we can extend append() to handle this. you have to build your
> > > array in php and assign it then to smarty for now.
> >
> > Thanks for your reply messju, too bad I didn't get a "you are such a fool,
> > see how easy it is" :-)
> >
> >
> > Greets,
> > Joscha
> > P.S.: Perhaps if we all shout "here", we get Monte to include it in the next
> > CVS :-D
>
> maybe:
>
> here is what i suggest: give the key as an optional third parameter.
> you still have to append your values each (with foreach), otherwise it
> wouldn't be compatible (there are people that want to append and array
> as a single value! :), but so it is possible to append with arbitrary
> keys.
>
> here is my diff (so i shout "here, me too!" :)
>
>
> Index: Smarty.class.php
> ===================================================================
> RCS file: /repository/smarty/Smarty.class.php,v
> retrieving revision 1.349
> diff -r1.349 Smarty.class.php
> 604c604
> < function append($tpl_var, $value = null)
> ---
> > function append($tpl_var, $value = null, $key=null)
> 607,610c607,610
> < foreach ($tpl_var as $key => $val) {
> < if ($key != '') {
> < if(!@is_array($this->_tpl_vars[$key])) {
> < settype($this->_tpl_vars[$key],'array');
> ---
> > foreach ($tpl_var as $name=>$val) {
> > if ($var_name != '') {
> > if(!@is_array($this->_tpl_vars[$name])) {
> > settype($this->_tpl_vars[$name],'array');
> 612c612,615
> < $this->_tpl_vars[$key][] = $val;
> ---
> > if (isset($key))
> > $this->_tpl_vars[$name][$key] = $val;
> > else
> > $this->_tpl_vars[$name][] = $val;
> 620c623,626
> < $this->_tpl_vars[$tpl_var][] = $value;
> ---
> > if (isset($key))
> > $this->_tpl_vars[$tpl_var][$key] = $value;
> > else
> > $this->_tpl_vars[$tpl_var][] = $value;
> 631c637
> < function append_by_ref($tpl_var, &$value)
> ---
> > function append_by_ref($tpl_var, &$value, $key=null)
> 637c643,646
> < $this->_tpl_vars[$tpl_var][] = &$value;
> ---
> > if (isset($key))
> > $this->_tpl_vars[$tpl_var][$key] = &$value;
> > else
> > $this->_tpl_vars[$tpl_var][] = &$value;
>
> HTH
> messju
--
Monte Ohrt <monte@ispi.net>