|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
tatya Smarty n00b
Joined: 16 Dec 2010 Posts: 3
|
Posted: Thu Dec 16, 2010 10:21 pm Post subject: Fatal error: Using $this when not in object context |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Dec 16, 2010 11:35 pm Post subject: |
|
|
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 |
|
tatya Smarty n00b
Joined: 16 Dec 2010 Posts: 3
|
Posted: Fri Dec 17, 2010 12:02 am Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Dec 17, 2010 4:25 am Post subject: |
|
|
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 |
|
huutri Smarty Rookie
Joined: 08 Feb 2011 Posts: 7
|
Posted: Thu Feb 10, 2011 4:50 am Post subject: Need help fix this error |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Feb 10, 2011 10:59 pm Post subject: |
|
|
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 |
|
|
|
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
|