如何为 CodeIgniter 设置 date.timezone 以使用 php 5.3 [英] How to set date.timezone for CodeIgniter to work with php 5.3

查看:30
本文介绍了如何为 CodeIgniter 设置 date.timezone 以使用 php 5.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当 php.ini 中的 date.timezone 被注释掉时,它给了我:

When date.timezone in php.ini is commented out, it gives me:

遇到 PHP 错误

严重性:警告

消息:main():这是不安全的依赖系统的时区设置.您必须使用date.timezone 设置或date_default_timezone_set() 函数.如果您使用了这些方法中的任何一种你仍然得到这个警告,你很可能拼错了时区标识符.我们选择了'America/Los_Angeles' 为 '-8.0/no夏令时'代替

Message: main(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for '-8.0/no DST' instead

文件名:controllers/helloworld.php

Filename: controllers/helloworld.php

行号:2

当我有

date.timezone = "America/Los_Angeles"

它给了我这个:

服务器错误 网站遇到检索时出错http://localhost/ci/index.php/helloworld.它可能因维护而停机或配置不正确.这里有一些建议:重新加载此网页之后.HTTP 错误 500(内部服务器错误):意外情况是在服务器运行时遇到尝试完成请求.

Server error The website encountered an error while retrieving http://localhost/ci/index.php/helloworld. It may be down for maintenance or configured incorrectly. Here are some suggestions: Reload this web page later. HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

我使用的是 php 5.3、CodeIgniter 2.0.0 和 Apache 2.2.

I am using php 5.3, CodeIgniter 2.0.0, and Apache 2.2.

更新 1:我尝试在没有 CodeIgniter 的情况下加载 test.php,其中 test.php 的前 3 行是

Update 1: I tried loading a test.php without CodeIgniter, where the first 3 lines of test.php is

date_default_timezone_set('America/Los_Angeles');
echo date("l j of F Y h:i:s A");

而且它工作正常,不同的时区也工作正常.所以我怀疑问题出在 CodeIgniter 上.

And it works fine, different timezones also works fine too. So I suspect the problem is from CodeIgniter.

推荐答案

如果您在 Google 上搜索CodeIgniter PHP 5.3",您会很快找到这篇文章:)

If you Googled "CodeIgniter PHP 5.3" you would have found this article pretty quickly :)

http://philsturgeon.co.uk/blog/2009/12/CodeIgniter-on-PHP-5.3

要解决此问题,您只需编辑 CodeIgniter 应用程序的主 index.php:

To fix this, you only need to edit the main index.php for your CodeIgniter application:

if( ! ini_get('date.timezone') )
{
   date_default_timezone_set('GMT');
} 

对于在 PHP 5.3 上运行的任何 CodeIgniter 应用程序,您可能需要进行此修改,并且可以轻松地将其修改为您的本地时区.PHP 手册中有支持的时区的完整列表这里.

This modification is something you will probably need to make for any CodeIgniter application running on PHP 5.3 and can easily be modified to your local timezone. There is a full list of supported timezones in the PHP manual here.

这篇关于如何为 CodeIgniter 设置 date.timezone 以使用 php 5.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆