【问题标题】:Timezone settings problem in codeignitercodeigniter中的时区设置问题
【发布时间】:2012-12-21 10:51:35
【问题描述】:

我正在尝试使用 PHP 5.3.5 和 2.0.2 CI 在我的 WAMP 上设置 CodeIgniter。我的“Hello World”应用程序成功运行(我只有一个控制器和视图)。接下来我添加了一个模型 test.php

class Tests extends CI_Model {

    function __construct() {    
        parent::__contruct();
    }
}

我在控制器中将模型实例化为:

$this->load->model('Tests');  

但我不断收到此错误:

依赖系统的时区设置是不安全的。

如何解决此错误?我尝试在 php.ini 中设置 date.timezone 属性。我还尝试在 CI 的 index.php 中调用 date_default_timezone_set 方法。我确实浏览了 CI 论坛,但似乎每个人都通过致电 date_default_timezone_set 解决了这个问题。但是当我调用该方法时,我什至没有得到错误。相反,我收到了来自 Apache 的 500 服务器错误响应!

PHP 和 CI 专家.. 我需要你的帮助。


最新更新

我启用了日志记录以查看在垫子下的运行情况。这是我的模型:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    class Hello extends CI_Model {

        function __construct()
        {
            log_message('debug', "Staring Hello Model");
            parent::__construct();
            log_message('debug', "Done with Hello Model");
        }
    }

我的控制器:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Hello extends CI_Controller {

    public function index()
    {
        //$this->load->view('hello');
        echo phpinfo(); 
    }

    public function newfun()
    {
        log_message('debug', "Starting new method...");
        $this->load->model('hello');
        log_message('debug', "Completed model load...");
        $this->load->view('hello');
    }
}

还有我的日志文件:

DEBUG - 2011-04-18 15:01:44 --> Config Class Initialized
DEBUG - 2011-04-18 15:01:44 --> Hooks Class Initialized
DEBUG - 2011-04-18 15:01:44 --> Utf8 Class Initialized
DEBUG - 2011-04-18 15:01:44 --> UTF-8 Support Enabled
DEBUG - 2011-04-18 15:01:44 --> URI Class Initialized
DEBUG - 2011-04-18 15:01:44 --> Router Class Initialized
DEBUG - 2011-04-18 15:01:44 --> Output Class Initialized
DEBUG - 2011-04-18 15:01:44 --> Security Class Initialized
DEBUG - 2011-04-18 15:01:44 --> Input Class Initialized
DEBUG - 2011-04-18 15:01:44 --> Global POST and COOKIE data sanitized
DEBUG - 2011-04-18 15:01:44 --> Language Class Initialized
DEBUG - 2011-04-18 15:01:44 --> Loader Class Initialized
DEBUG - 2011-04-18 15:01:44 --> Controller Class Initialized
DEBUG - 2011-04-18 15:01:44 --> Starting new method...
DEBUG - 2011-04-18 15:01:44 --> Model Class Initialized

最后的日志输出来自 ci/system/core 文件夹中 Model.php 的构造函数。没有迹象表明我的模型的控制器正在执行(我没有看到来自模型的任何日志消息)。

我的模型有什么问题?我是正确编码还是忽略了一些愚蠢的事情?

【问题讨论】:

  • 您的模型中是否有任何代码调用任何日期函数?你能粘贴整个构造代码吗?
  • 我已经提供了完整的代码!除了构造函数之外,没有其他属性或方法。我打算稍后使用模型从数据库中获取数据...
  • 哇,真奇怪!如果删除 parent::_construct 代码会发生什么?
  • 没有变化..我什至在CI论坛codeigniter.com/forums/viewthread/186740上发布了它
  • 但是,一旦您删除控制器中的负载->模型,问题就消失了吗?

标签: php codeigniter-2


【解决方案1】:

可能是命名冲突?或者是命名问题(CI 对模型/控制器和视图名称中的小写大写非常具体)。

你可以试试,'goodbye_model.php'(小写)和模型的主线'class Goodbye_model extends CI_Model'并加载'Goodbye_model'(大写优先)。

并确保文件名是小写的,并且类名是第一个大写的。

【讨论】:

    猜你喜欢
    • 2023-03-26
    • 1970-01-01
    • 2011-08-27
    • 2013-06-29
    • 2017-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多