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

Passing session objects to smarty

 
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 -> Tips and Tricks
View previous topic :: View next topic  
Author Message
terryjohnson
Smarty Rookie


Joined: 03 Jan 2004
Posts: 9
Location: Chatham, ON, Canada

PostPosted: Tue Feb 10, 2004 2:42 am    Post subject: Passing session objects to smarty Reply with quote

If your application caches several objects in the user session that you also need to pass to Smarty for display, you can do it at the same time as checking the session hasn't been corrupted or timed out, using assign_by_ref. You can still call methods and change the properties of your objects in the rest of the script, and all your changes will show up when you display the page.

Code:
$req_items = array(
    'customer'=>'MyCustomer',
    'locale'=>'LocaleData',
    'basket'=>'MyOrderBasket',
    'prefs'=>'MyPrefs',
    'etc'=>'MyEtc');
foreach ($req_items as $item => $class) {
    if (!isset($_SESSION[$item]) || !is_a($_SESSION[$item],$class)) {
        // raise error or redirect to timeout page
    } else {
        $smarty->assign_by_ref($item,$_SESSION[$item]);
    }
}


Enjoy!

Terry Johnson
Developer
http://www.scribendi.com
Back to top
View user's profile Send private message Visit poster's website
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 -> Tips and Tricks 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