如何设置CodeIgniter的date.timezone与php 5.3一起使用 [英] How to set date.timezone for CodeIgniter to work with php 5.3

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

问题描述

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

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

遇到PHP错误

A PHP Error was encountered

严重性:警告

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

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的前三行是

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应用程序编辑main.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天全站免登陆