Re: [SMARTY] Problems with appending values to an array
| From: | Monte Ohrt | Date: | Wed, 19 Feb 2003 23:10:43 +0000 |
| Subject: | Re: [SMARTY] Problems with appending values to an array | ||
| References: | 1 2 3 4 5 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-7956@lists.php.net to get a copy of this message | ||
Actually I think this can be done a bit cleaner.
I backed out the patch, removing the third 'key' parameter.
You can now merge arrays with append by passing an array as the value.
example:
$smarty->assign('foo','bar);
$smarty->append('foo',array('do','re','mi','fa'));
If you want to append key/vals:
$smarty->append('foo',array('do' => 're','mi' =>
'fa'));
I didn't change the append_by_ref, I don't think that is necessary since
it is a reference anyways.
But give it a try, see if everything works OK.
Monte
On Wed, 2003-02-19 at 11:19, messju mohr wrote:
> On Wed, Feb 19, 2003 at 10:40:23AM -0600, Monte Ohrt wrote:
> > here here!
> >
> > committed.
>
> great :) thanks.
>
> > 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>
>
> --
> Webstuhl: Vornehme Ausdrucksweise für die Scheiße, die Webdesignsoftware
> auswirft.
> Holger Veit
--
Monte Ohrt <monte@ispi.net>