Basically in codeigniter, how can i use the system and application libraries within other libraries? So say I have a application library such as:
class User
{
// some instance variables
}
Now lets say I want to use codeigniter session class in the User class, basically being able to work with sessions inside the User class. How can I go about doing this?
The typical way to do this is to use
get_instance(), which returns an instance of Codeigniter (actually the current controller class).This will work from anywhere in your CI application:
Typically in Codeigniter, you assign it to a class variable for ease of use:
This does create a lot of dependency on the state of CI and the different loaded classes, rather than passing instances of them in directly to the User class via Dependency Injection, but this is the typical flow for someone developing a CI library.