Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZendFramework 2 : Set date_default_timezone

I am new to the Zend Framework 2 and would like to simply know if there is a global way of setting the date default timezone.

I am aware that i should just be able to add the code:

date_default_timezone_set("UTC");

However i have been looking for about an hour and can't find an answer addressing this issue.

I have also tried by setting this in the php.ini but i'm not sure if this would suppress the error message.

Thanks in advance.

like image 355
Liam Sorsby Avatar asked Mar 24 '26 11:03

Liam Sorsby


1 Answers

My "elegant way" is overwriting php settings from config file using onBootstrap. Inside my global.php I add the php settings I need to set up for the app:

return array(
   'php_settings' => array(
       'date.timezone' => 'UTC',
       'memory_limit' => '128M',
       'display_errors' =>'On'
   )
);

Then, onBootstrap:

    //Enable php settings from config file into the web app
    $services = $e->getApplication()->getServiceManager();
    $config = $services->get('config');        
    $phpSettings = $config['php_settings'];
    if ($phpSettings) {
        foreach ($phpSettings as $key => $value) {
            ini_set($key, $value);
        }
    }
like image 188
Conti Avatar answered Mar 27 '26 02:03

Conti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!