saving data via __destruct - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: saving data via __destruct (/showthread.php?tid=25266) |
saving data via __destruct - El Forum - 12-06-2009 [eluser]gino[/eluser] Hi, i'm still learning CI and not yet an expert in PHP i was just wondering if it's possible to save data into the database in the magic __destruct function? example: Code: <?php i'm just not sure if this is a good thing todo! and if the code will always be excecuted?!! any experts please give me your thoughts. thnx in advance! saving data via __destruct - El Forum - 12-06-2009 [eluser]umefarooq[/eluser] if you want to update you table every time when object is getting destroy then it is ok, please check the following link http://php.net/manual/en/language.oop5.decon.php saving data via __destruct - El Forum - 12-06-2009 [eluser]gino[/eluser] thnx, i already read the docs on php.net, but i'm just still a litle confused on when the destructor is actually called. maybe a litle paranoid to! it's not possible that the CI->db object doesn't exist anymore? saving data via __destruct - El Forum - 12-07-2009 [eluser]umefarooq[/eluser] hi just try this simple class Code: <? saving data via __destruct - El Forum - 12-07-2009 [eluser]Namaless[/eluser] Use register_shutdown_function(array($this,"my_destruct_method")) ^_^ saving data via __destruct - El Forum - 12-07-2009 [eluser]gino[/eluser] [quote author="Namaless" date="1260194298"]Use register_shutdown_function(array($this,"my_destruct_method")) ^_^[/quote] thnx for the reply! i'm currently looking into this method also @umefarooq thnx for the example, everything works as expected! appreciated :-) |