CI Sessions and Smarty - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: CI Sessions and Smarty (/showthread.php?tid=34090) |
CI Sessions and Smarty - El Forum - 09-18-2010 [eluser]Unknown[/eluser] Hi All, Since you are reading this, I suppose you're looking for a fancy solution to implement the famous (or infamous) CI sessions into your Smarty template parser. Well, after reading a couple of posts about how other users have implemented this. I decided to create my very own solution. For starters, my application/libraries directory is very clean. It only has the s.php classfile which implements smarty into the CI framework, and the folder "smarty" for all the smarty-internal-files. My s.php file looks like this: Code: <?php Code: $autoload['libraries'] = array('database', 'session', 's'); To take my CI session object, and assign it to a template, I used a 'hook'. If you're not familiar with hooks, please check the user_guide. To enable hooks, set $config['enable_hooks'] = TRUE; in config/config.php To add a hook, modify config/hooks.php and add the following: Code: $hook['post_controller'][] = array( Now, let's add the code for the hook (hooks/smartyhook.php): Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); The advantage of this method is: you never have to call the default template to display in your methods. And, if you want to display another template, you just assign the name to your session. So, this is my solution. For every project a slight modification might be needed, but in general, this method works for me. Hope you'll like it. |