RE: [SMARTY] (Fwd) Re: [SMARTY] adding vars to array

From: Date: Fri, 12 Jul 2002 14:39:31 +0000
Subject: RE: [SMARTY] (Fwd) Re: [SMARTY] adding vars to array
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-5270@lists.php.net to get a copy of this message
I WILL disable error_reporting when I publish my site, because errors/notices/warnings can be useful for hackers/.. if you are using header(), so they can see some outputs of restricted areas. Thanks for the tip :) Peter -----Original Message----- From: Ferdinand Beyer [mailto:fbeyer@clickhand.de] Sent: vrijdag 12 juli 2002 16:30 To: peter@clueless.be Subject: RE: [SMARTY] (Fwd) Re: [SMARTY] adding vars to array Are you using debugging? Try to use E_ALL ^ E_NOTICE as the current Smarty releases will often produce notices. I think following produces a notice, too: {$unset|default:'Variable unset is not set'} But your way to assign the array before using append() is of course a good and clean method. On 12 Jul 2002 at 16:18, Peter Billen wrote: > Woops, i was a little bit too quick with my mail :) > > I have found a workaround, it works, but I don't know it's a good method > :) > > : > > $t = new Smarty(); > > $db->query(...); > > $t->assign("topic",array()); /* ADDED */ > > while ($row = $db->fetch_array()) > { > $t->append("topic",$row['...']); > } > > if ($db->num_rows()) > $t->display("..."); > > Peter > > -----Original Message----- > From: Peter Billen [mailto:peter@clueless.be] > Sent: vrijdag 12 juli 2002 16:16 > To: smarty-general@lists.php.net > Subject: RE: [SMARTY] (Fwd) Re: [SMARTY] adding vars to array > > Thanks, i have tried it and it works, BUT: > > Since I'm coding with error_reporting('E_ALL'); it gives an error (a > notice actually) when I use this method. It says: Undefined index: topic > in C:\...\Smarty.class.php on line 248. > > I think this has something to do when I call this function for the first > time, so the array doesn't exist yet? I think that because this notice > is only given once. > > My code: > > --- > $t = new Smarty(); > > $db->query(...); > > while ($row = $db->fetch_array()) > { > $t->append("topic",$row['...']); > } > > if ($db->num_rows()) > $t->display("..."); > > --- > > Peter > > -----Original Message----- > From: Ferdinand Beyer [mailto:fbeyer@clickhand.de] > Sent: vrijdag 12 juli 2002 16:11 > To: smarty-general@lists.php.net > Subject: [SMARTY] (Fwd) Re: [SMARTY] adding vars to array > > On 12 Jul 2002 at 14:03, Peter Billen wrote: > > > Is it possible to add vars to an array with using Smarty, so I can do > > something like: > > > > $t = new Smarty(); > > > > $db->query(". my sql query ."); > > > > while ($row = $db->fetch_array()) > > { > > $t->addvar("date",$row['field1']); > > . > > } > > > > if ($db->num_rows()) > > $t->display(.) > > Use Smarty's append() method for that: > > while ($row = $db->fetch_array()) { > $t->append("date", $row['field 1']); > } > > This produces the template variable $date - an array - and pushes > values to it: > > $t->append('arr', 'Zero'); > $t->append('arr', 'One'); > $t->append('arr', 'Two'); > ======================================== > {foreach loop=$arr key="key" item="value"} > {$key} - {$value}<br /> > {/foreach} > > Outputs: > > 0 - Zero > 1 - One > 2 - Two > > (not tested, should work) > > Please look up the append() method in the docs for further details. > > -- > Ferdinand Beyer > <fbeyer@clickhand.de>-- > Ferdinand Beyer > <fbeyer@clickhand.de> > > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Ferdinand Beyer <fbeyer@clickhand.de>

« previous php.smarty.general (#5270) next »