![]() |
How to reload a custom library - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11) +--- Thread: How to reload a custom library (/showthread.php?tid=68065) |
How to reload a custom library - zashishz - 05-19-2017 I have created a custom library which depends on session data. In my main controller i am initializing session values and want to reload custom library based on new values every time page is refreshed. Hence, i am using session_destroy(); at the end of my controller method. But on page refresh library are not reloaded : Code: closeOrders class already loaded. Second attempt ignored. Is there any way i can reload some library again on page refresh. RE: How to reload a custom library - Martin7483 - 05-19-2017 (05-19-2017, 03:51 AM)zashishz Wrote: This has nothing todo with a page reload. This means you are loading that library twice PHP Code: $this->load->library('closeOrders'); Because a resource is appended to the CI super object, you can't load a resource twice. If you provide an alias name for a library as a third argument when loading it, CI will create a new instance of that class and append it to the super object using the provided alias. You can also just do this PHP Code: $second_closeOrders_object = new closeOrders(); Because the file is loaded into memory you can create a new instance of the class where ever you may need it. If you don't want to do this, and want to re-use the first instance, create a method in the library that resets it be clearing all the variables PHP Code: $this->closeOrders->clear($new_values); RE: How to reload a custom library - zashishz - 05-24-2017 (05-19-2017, 03:51 AM)zashishz Wrote: I have created a custom library which depends on session data. Thanks for the reply. I wanted to reload library to populate with updated session data. Now using Session Flash Data to refresh data on every request and its working fine. https://www.codeigniter.com/user_guide/libraries/sessions.html?highlight=flash#CI_Session::flashdata Thanks for the help. |