Welcome Guest, Not a member yet? Register   Sign In
get_instance
#1

[eluser]sikkle[/eluser]
Hello again Smile

Someone here can give some advice kind of light resume about what is it ?, why and how ?


thanks again.
#2

[eluser]chobo[/eluser]
The get instance just returns a reference to the CI object which contains all the CI settings and objects (tons of stuff). As far as I know you only need to get a reference to the object when you are working in your own classes (referred to as libraries). If your in a model, view or controller you can access the values in the CI object without getting a reference (instance).
#3

[eluser]esra[/eluser]
Do a web search on the registry design pattern. The user_guide refers to it as the CI super object, but it is referred to as the registry in either common.php or codeigniter.php. A registry object stores any number of objects and variables, allowing them to be accessed globally within an application.
#4

[eluser]esra[/eluser]
The Front Controller instantiates an instance of the registry when a user accesses your site.

You also need to get a reference when you need to access objects or variables in the registry from a plugin or helper. For example and among other things, you need to get a reference when accessing the database object (dbo) from a helper.
#5

[eluser]chobo[/eluser]
The get_instance also implies it is using the singleton pattern to persist the object (global variable/object)




Theme © iAndrew 2016 - Forum software by © MyBB