|
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 |
terryjohnson Smarty Rookie
Joined: 03 Jan 2004 Posts: 9 Location: Chatham, ON, Canada
|
Posted: Tue Feb 10, 2004 2:42 am Post subject: Passing session objects to smarty |
|
|
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 |
|
|
|
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
|