Get the CI singleton
public static get_instance ( ) : object | ||
return | object |
class My_Controller extends CI_Controller { public function my_method() { // Get a reference to the database library $db = $this->load->database(); // Use the database to query some data $query = $db->get('users'); $result = $query->result_array(); // Send the data to the view $this->load->view('my_view', $result); } }
class My_Controller extends CI_Controller { public function my_method() { // Get a reference to the session library $session = $this->load->library('session'); // Set a custom configuration value for the session library $this->session->set_userdata('custom_value', '12345'); // Display the custom value echo $this->session->userdata('custom_value'); } }In this example, we are using `get_instance()` to get a reference to the CI_Controller instance, and then using the `load->library()` method to load the session library. We can then set a custom configuration value for this library using the `set_userdata()` method. Finally, we can display the custom value using the `userdata()` method. Package/library: CodeIgniter Session Library Overall, `get_instance()` method is a useful tool in CodeIgniter that allows you to access the various libraries and functions within the framework. By understanding how to use this method, you can gain greater control over your CodeIgniter applications and make them more efficient and powerful.