how to make variables in pre_controller hooks global to all controllers? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: how to make variables in pre_controller hooks global to all controllers? (/showthread.php?tid=29673) |
how to make variables in pre_controller hooks global to all controllers? - El Forum - 04-17-2010 [eluser]ajsie[/eluser] in my pre_controller hook i have this code for doctrine: $manager = Doctrine_Manager::getInstance(); $conn = Doctrine_Manager::connection($db[$active_group]['dsn']); then in my controller i have this code to use doctrine connection i've created: $conn->export->createTable('test', array('name' => array('type' => 'string'))); $conn->execute('INSERT INTO test (name) VALUES (?)', array('jwage')); but $conn is undefined so it wont work. if i put the code in the pre_controller hook it will work. how can i make variables i declare in hooks available for all controllers so that i dont have to create a new connection all the time? how to make variables in pre_controller hooks global to all controllers? - El Forum - 04-17-2010 [eluser]umefarooq[/eluser] create a MY_Controller in library and extend you Controllers with you MY_Controller Code: class MY_Controller extends Controller{ how to make variables in pre_controller hooks global to all controllers? - El Forum - 04-17-2010 [eluser]ajsie[/eluser] thanks. ill do that. but what if i want to use it in a model or another class for some reasons? how to make variables in pre_controller hooks global to all controllers? - El Forum - 04-17-2010 [eluser]umefarooq[/eluser] the also do the same thing it will work really fine for more information read this article will help you more http://philsturgeon.co.uk/news/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY |