When to use get_instance - 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: When to use get_instance (/showthread.php?tid=26726) |
When to use get_instance - El Forum - 01-21-2010 [eluser]vertmonkee[/eluser] I am just looking at creating my own library. I believe there are authentication libraries avilable but I'm keen to use this as a first try of writing my own library. The question I have is about when to use get_instance, if I have a class as follows Code: if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Do I have to use get_instance in all of my methods or can I just include it once and have all methods access it? If so hwo do I acheive this? Thanks for any help When to use get_instance - El Forum - 01-21-2010 [eluser]danmontgomery[/eluser] The instance is returned, not declared globally, so you can only use it in the scope which it's called. If you want to use it throughout the class, declare it in the constructor as a class member. Code: class Authentication { Or, you can define it locally in each method you want to use it, like in your example. When to use get_instance - El Forum - 01-21-2010 [eluser]vertmonkee[/eluser] Wow thanks for your super quick reply. That has completley cleared that up for me. Thanks very much. |