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

Fatal error: Using $this when not in object context

 
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 -> Bugs
View previous topic :: View next topic  
Author Message
tatya
Smarty n00b


Joined: 16 Dec 2010
Posts: 3

PostPosted: Thu Dec 16, 2010 10:21 pm    Post subject: Fatal error: Using $this when not in object context Reply with quote

Fatal error: Using $this when not in object context in C:\AppServ\www\Project\XXX\plugins\block.php.php(23) : eval()'d code on line 7

i have this message when i insert this code to the template :
{php}
$id = '5&house';
$x = base64_encode($id);
$this->assign('var',$x );
{/php}

pleaz help me!!!
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Dec 16, 2010 11:35 pm    Post subject: Reply with quote

The use of PHP code within templates is decripated.

Why do you need it?

Code:
{$var=base64_encode('5&house')}

will do same thing.
Back to top
View user's profile Send private message
tatya
Smarty n00b


Joined: 16 Dec 2010
Posts: 3

PostPosted: Fri Dec 17, 2010 12:02 am    Post subject: Reply with quote

because i want assign a variabl from {php} block


{php}
$query = mysql_query('SELECT close FROM options') or die ("error");
$impo = mysql_fetch_assoc($query);
$siteclose = $impo['close'];
mysql_free_result($query);
if($siteclose == 0){
$statu = "Site closed";
}else{
$statu = "Site is open";
}
{/php}
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Dec 17, 2010 4:25 am    Post subject: Reply with quote

Do this SQL stuff in PHP, either outside of Smarty entirely or at least in a plugin. See the example app link on the Smarty site for an example. Embedding PHP in Smarty templates defeats the purpose of using Smarty.
Back to top
View user's profile Send private message Visit poster's website
huutri
Smarty Rookie


Joined: 08 Feb 2011
Posts: 7

PostPosted: Thu Feb 10, 2011 4:50 am    Post subject: Need help fix this error Reply with quote

Hi All

I also get this error but i dont understand to fix it? If anyone has solution to fix it, Please help me
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Feb 10, 2011 10:59 pm    Post subject: Reply with quote

replace $this->... within {PHP} tags by $template->....

However {PHP} are decripate because of security risks.
It's better to place the code in a function plugin.
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 -> Bugs 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