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 I do $smarty->assign(); from within php functions

 
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
lean4huskytop
Smarty Regular


Joined: 19 Aug 2003
Posts: 41

PostPosted: Wed Aug 27, 2003 7:28 pm    Post subject: can I do $smarty->assign(); from within php functions Reply with quote

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
View user's profile Send private message
gianni
Smarty Rookie


Joined: 14 May 2003
Posts: 29
Location: Bari, Italy

PostPosted: Wed Aug 27, 2003 7:38 pm    Post subject: Reply with quote

try to add in your function:

global $tpl;
_________________
PHPnews.it Notizie dal mondo PHP e dintorni
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
lean4huskytop
Smarty Regular


Joined: 19 Aug 2003
Posts: 41

PostPosted: Wed Aug 27, 2003 8:18 pm    Post subject: error I am getting Reply with quote

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
View user's profile Send private message
wvdploeg
Smarty Rookie


Joined: 05 Aug 2003
Posts: 19

PostPosted: Mon Sep 01, 2003 5:24 pm    Post subject: Re: error I am getting Reply with quote

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
View user's profile Send private message
lean4huskytop
Smarty Regular


Joined: 19 Aug 2003
Posts: 41

PostPosted: Mon Sep 01, 2003 6:17 pm    Post subject: hey Reply with quote

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
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