简体   繁体   English

让 FuelPHP 观察者使用 MySQL 日期时间

[英]Getting FuelPHP observers to use MySQL datetimes

I was trying to get the FuelPHP ORM Observers to use MySQL datetimes rather than unix timestamps, however I can't figure out how to use the code provided in the docs.我试图让 FuelPHP ORM 观察者使用 MySQL 日期时间而不是 unix 时间戳,但是我不知道如何使用文档中提供的代码。

They provide this code: Orm\Observer_CreatedAt::$mysql_timestamp = true;他们提供以下代码: Orm\Observer_CreatedAt::$mysql_timestamp = true;

But where do I use this?但是我在哪里使用这个? In the model?在model? It doesn't seem to work there.它似乎在那里不起作用。

Thanks!谢谢!

This is something that was put in a bit hacky and should have been a config value from the beginning, something we'll fix for 1.1.这是一个有点骇人听闻的东西,从一开始就应该是一个配置值,我们将在 1.1 中修复它。

Best way to do it right now is probably to give the models using the CreatedAt/UpdatedAt observers an _init() method like the code below.现在最好的方法可能是为使用 CreatedAt/UpdatedAt 观察者的模型提供一个_init()方法,如下面的代码。 The init method is called by the autoloader after loading the class.加载 class 后,自动加载器会调用 init 方法。

public static function _init()
{
    Orm\Observer_CreatedAt::$mysql_timestamp = true;
    Orm\Observer_UpdatedAt::$mysql_timestamp = true;
}

Btw asking a question on our forums or on IRC will probably get you faster answers.顺便说一句,在我们的论坛或 IRC 上提问可能会让您更快得到答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM