Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Can only use object once from assign_by_ref() or assign()

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
ZeroFill
Smarty Rookie


Joined: 31 Aug 2003
Posts: 28

PostPosted: Sun Sep 21, 2003 11:38 pm    Post subject: Can only use object once from assign_by_ref() or assign() Reply with quote

I'm having trouble re-using an object that was assign_by_ref() or assign()in the same script.

[php:1:811eea1d06]
//index.php
$news = new News();
$smarty->assign_by_ref('news',$news);
$smarty->display('headline.tpl');
[/php:1:811eea1d06]

Code:

//header.tpl (slightly modified to show the example; same loop ran twice)

<table width="100%" cellpadding="0" cellspacing="0">
<{foreach from=$news->get_news() item=news key=key}>   
   <tr>
      <td><{$news.date_post|date_format:"%m/%d"}></td>
      <td width="5px">&</td>
      <td><a href="#<{$key}>"><{$news.subject}></a></td>
      <td width="5px">&</td>
      <td align="right"><{$news.user}></td>
   </tr>
<{/foreach}>
</table>

<table width="100%" cellpadding="0" cellspacing="0">
<{foreach from=$news->get_news() item=news key=key}>   
   <tr>
      <td><{$news.date_post|date_format:"%m/%d"}></td>
      <td width="5px">&</td>
      <td><a href="#<{$key}>"><{$news.subject}></a></td>
      <td width="5px">&</td>
      <td align="right"><{$news.user}></td>
   </tr>
<{/foreach}>
</table


gives the error
Code:

     
 09/21   test 321   
09/21   Testing 123   
09/19   Anime   
09/19   Whats This? New Citys?   
09/17   Ok its a start.   

Fatal error: Call to a member function on a non-object in /home/geeks/projects/wow_website/templates/compiled/default/%%-17/%%-1787548953/headline.tpl.php on line 22


does anyone know why smarty is preventing me from re-using the object?

[php:1:811eea1d06]
// class.News.php snippet
function get_news()
{
return LoadStoreData::news_get(LoadStoreData::get_num_news_days());
}

// static.LoadStoreData.php snippet
function news_get($num_news = 5)
{
if ($num_news = 'admin')
$SQL = 'SELECT * FROM news ORDER BY date_post DESC';
else
$SQL = 'SELECT * FROM news ORDER BY date_post DESC LIMIT '.$num_news;
$result = mysql_query($SQL)
or LoadStoreData::or_die($SQL,__FILE__,__LINE__);
while ($row = mysql_fetch_assoc($result))
{
$row['author'] = LoadStoreData::get_user_display_name($row['rel_uid']);
$return[] = $row;
}
return $return;
}
function get_num_news_days()
{
$SQL = 'SELECT config.value FROM config WHERE config.name = "num_news"';
$result = mysql_query($SQL)
or LoadStoreData::or_die($SQL,__FILE__,__LINE__);
return mysql_result($result,0,0);
}
[/php:1:811eea1d06]
_________________
my delimiters are <{ and }>
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Sep 22, 2003 7:16 am    Post subject: Re: Can only use object once from assign_by_ref() or assign( Reply with quote

ZeroFill wrote:
Code:

...<{foreach from=$news->get_news() item=news key=key}>...


with "item=news" your overide your original $news.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ZeroFill
Smarty Rookie


Joined: 31 Aug 2003
Posts: 28

PostPosted: Mon Sep 22, 2003 7:21 am    Post subject: Reply with quote

LOL. i didn't notice that. thanks

i'll go stand in the corner for a while Embarassed
_________________
my delimiters are <{ and }>
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP