php - Magento 1.6 : Using MySQL datetime fields with resource models

标签 php mysql magento

我已经建立了一个数据库表,其中包含一个名为“release_date”的 DATETIME 字段,并且模型/资源模型似乎工作正常。但是,我想检索并将“release_date”设置为 Zend_Date 对象。我还想确保它始终以 UTC 格式存储和检索。

您对我如何做到这一点有什么建议,或者有更好的解决方案吗?

最佳答案

你可以在你的资源模型中处理它,像这样:

protected function _beforeSave(Mage_Core_Model_Abstract $object)
{
    ...
    $date = $object->getReleaseDate();
    // convert from your server/client timezone to UTC if needed
    $object->setReleaseDate($this->formatDate($date));
    ...
}

protected function _afterLoad(Mage_Core_Model_Abstract $object)
{
    ...
    $date = new Zend_Date($object->getReleaseDate());
    // convert to your server/client timezone from UTC if needed
    $object->setReleaseDate($date);
    ...
}

关于php - Magento 1.6 : Using MySQL datetime fields with resource models,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9233768/

相关文章:

php - Magento 中 CMS 页面的自定义字段

php - 优化查询(2个坐标之间的距离)

php - sql select如何调用函数?

PHP 在类外的函数中重用 MySQL 对象

mysql - 当我尝试在 phpMyAdmin Designer 工具中创建表之间的关系时出现错误 : Missing index on column(s).

mysql - 如何使用sql查找第二和第三大?

php - 如何将自定义属性值应用于成本

magento - 如何将文件夹添加到resource_config.json中的 "allowed_resources"?

php - 订购 while 循环数据

php - 带有简单查询的sql语法错误