I found this thread to be very useful in solving an issue I was having, and I thought I’d share it incase others find this useful or are in similar situations.
For my application I wanted to be able to define a different timezone for each organization entity in my database schema.
In addition to setting the Database connection to use a specific timezone I also wanted to set PHP to use the same timezone so I wasn’t tied to the server timezone (and also because of the organization specific settings)
I ended up implementing this is a post_controller_constructor hook to set both PHP and Database settings.
public function set_timezone()
$CI =& get_instance();
$orgID = $CI->Organization->GetOrgIDFromSubdomain();
$query = $CI->db->query("
WHERE `OrganizationID` = '$orgID'
$row = $query->row();
// Where TimeZone is something like America/Vancouver
$timezone = $row->Timezone;
$hook['post_controller_constructor'] = array(
'class' => 'Timezone',
'function' => 'set_timezone',
'filename' => 'timezone.php',
'filepath' => 'hooks'