Procode Posted November 28, 2006 Share Posted November 28, 2006 Ok i am trying assign a var to smarty though my class. Here is the code:[code]function members_main(){ $smarty = new Smarty(); $sql = "SELECT * FROM `user` WHERE username = '".$_SESSION['user']."' LIMIT 1"; $mysql = new mysql(); $info = $mysql->assoc_array($sql); $smarty->assign('name', $_SESSION['user']); } function member_page(){ $smarty = new Smarty(); switch($_GET['do']){ default: $this->members_main(); $smarty->display('main.members.tpl'); break;[/code]Where you see [code]$this->members_main();[/code] if i replace that with [code]$smarty->assign('name', $_SESSION['user']);[/code] It works fine. But if i do it through [code]$this->members_main();[/code] it doesn't work. What am i doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/28693-once-again-need-help/ Share on other sites More sharing options...
btherl Posted November 28, 2006 Share Posted November 28, 2006 It looks to me like you are creating a new Smarty object in members_main(). That object will be destroyed when the function ends.If that's the case, you can fix it by passing $smarty into the function, or by making it a class variable. Quote Link to comment https://forums.phpfreaks.com/topic/28693-once-again-need-help/#findComment-131346 Share on other sites More sharing options...
Procode Posted November 28, 2006 Author Share Posted November 28, 2006 I dont understand, can you give an example? Quote Link to comment https://forums.phpfreaks.com/topic/28693-once-again-need-help/#findComment-131365 Share on other sites More sharing options...
Procode Posted November 28, 2006 Author Share Posted November 28, 2006 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/28693-once-again-need-help/#findComment-131512 Share on other sites More sharing options...
Procode Posted November 28, 2006 Author Share Posted November 28, 2006 Guess not. Quote Link to comment https://forums.phpfreaks.com/topic/28693-once-again-need-help/#findComment-131788 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.