Articles → PHP CODEIGNITER → get_instance method in codeigniterget_instance method in codeigniterIn this article, we will discuss the "get_instance" method in codeigniter.Purpose In codeigniter, $this is used to get an instance of the current class. The object $this works well if you are using the object in model, views or controller.But you cannot use $this inside your custom classes. You can use the get_instance method instead of $this object.Example Let us consider an example in which you want to call helper class in custom class. You can use the following code. $c = & get_instance(); $c->load->helper('date'); nice_date(NULL, NULL);In the above code 1. The first line gives the instance using the "get_instance" method. 2. Second line loads the helper. 3. Third line calls the method "nice_date".Posted By - Karan Gupta Posted On - Tuesday, July 28, 2020 Query/Feedback Your Email Id Subject Query/Feedback Characters remaining 250
$c = & get_instance(); $c->load->helper('date'); nice_date(NULL, NULL);
Query/Feedback