|
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 |
lean4huskytop Smarty Regular
Joined: 19 Aug 2003 Posts: 41
|
Posted: Wed Aug 27, 2003 7:28 pm Post subject: can I do $smarty->assign(); from within php functions |
|
|
I have this:
a class that extends smarty. I instantiate class:
$tpl = new Template_API();
then I do $tpl->assign(blabla); /// this works fine
now I have a function :
function tester(){
$tpl->assign(); // this does not work here any longer? why??????????
} |
|
Back to top |
|
gianni Smarty Rookie
Joined: 14 May 2003 Posts: 29 Location: Bari, Italy
|
Posted: Wed Aug 27, 2003 7:38 pm Post subject: |
|
|
try to add in your function:
global $tpl; _________________ PHPnews.it Notizie dal mondo PHP e dintorni |
|
Back to top |
|
lean4huskytop Smarty Regular
Joined: 19 Aug 2003 Posts: 41
|
Posted: Wed Aug 27, 2003 8:18 pm Post subject: error I am getting |
|
|
global $tpl;
$tpl = new Template_API();I did the global $tpl
but it still didnt work...
Fatal error: Call to a member function on a non-object in C:\FoxServ\www\TRAINER_DIRECTORY\formcheck.inc.php on line 5
my tpl definition:
global $tpl;
$tpl = new Template_API();
my function:
Code: |
function check_firstname(){
if ( strlen( trim($_REQUEST['txtboxFirstName'])) == 0){
$this->tpl->assign(error,true);
return "<li>You must enter your first name.<br />\n";
}
} |
|
|
Back to top |
|
wvdploeg Smarty Rookie
Joined: 05 Aug 2003 Posts: 19
|
Posted: Mon Sep 01, 2003 5:24 pm Post subject: Re: error I am getting |
|
|
lean4huskytop wrote: | global $tpl;
$tpl = new Template_API();I did the global $tpl
but it still didnt work...
Fatal error: Call to a member function on a non-object in C:\FoxServ\www\TRAINER_DIRECTORY\formcheck.inc.php on line 5
my tpl definition:
global $tpl;
$tpl = new Template_API();
my function:
Code: |
function check_firstname(){
if ( strlen( trim($_REQUEST['txtboxFirstName'])) == 0){
$this->tpl->assign(error,true);
return "<li>You must enter your first name.<br />\n";
}
} |
|
As far as I can see it, the function check_firstname() is a member function of a class, isn't it ? (if it isn't the '$this' makes no sense). So $tpl should be defined as an instance variable... did you do it ?
so something like
[php:1:e0a53dfd93]
class someClass {
var $tpl;
function someClass() {
$this->tpl = new template_API();
//someactions
}
function check_firstname() {
//other actions
}
}
[/php:1:e0a53dfd93]
Did you declare $tpl in a way as above ?
Last edited by wvdploeg on Tue Sep 02, 2003 5:20 pm; edited 1 time in total |
|
Back to top |
|
lean4huskytop Smarty Regular
Joined: 19 Aug 2003 Posts: 41
|
Posted: Mon Sep 01, 2003 6:17 pm Post subject: hey |
|
|
yes I did just what you did....
Dont worry about it...I have found a different way to solve the problem...I have to get going with the project, so I had to abandon this technique and see if i have time in the future to figure out what went wrong.
thanks for your feedback
Paul |
|
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
|