Welcome Guest, Not a member yet? Register   Sign In
saving data via __destruct
#1

[eluser]gino[/eluser]
Hi,

i'm still learning CI and not yet an expert in PHP Wink

i was just wondering if it's possible to save data into the database in the magic __destruct function?

example:

Code:
<?php

class Home extends Controller {

  private $mydata = array();

  public function __construct()
  {
    parent::Controller();
  }

  public function index()
  {
    $this->load->view('home');
    //data is added to the $this->mydata array
    //this could be done everywhere : views, models....
  }

  function __destruct()
  {
    $this->db->where('id', 1);
    $this->db->update('table', $this->mydata);
  }

}

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!


Messages In This Thread
saving data via __destruct - by El Forum - 12-06-2009, 07:45 AM
saving data via __destruct - by El Forum - 12-06-2009, 07:54 AM
saving data via __destruct - by El Forum - 12-06-2009, 08:03 AM
saving data via __destruct - by El Forum - 12-07-2009, 12:33 AM
saving data via __destruct - by El Forum - 12-07-2009, 01:58 AM
saving data via __destruct - by El Forum - 12-07-2009, 11:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB