Drupal 7模式中的日期时间类型 [英] Datetime type in Drupal 7 schema

查看:157
本文介绍了Drupal 7模式中的日期时间类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个新的Drupal 7模块(Drupal 7.10,安装了Date 7.x-2.0-rc1,安装了Schema 7.x-1.0-beta3)
i在mymodule.install中定义了一个表:

  $ schema ['museums_tickets'] = array(
'fields'=> array(
'nid '=>数组(
'type'=>'int',
'unsigned'=> TRUE,
'not null'=> TRUE,
) ,
'day'=> array(
'type'=>'datetime',
'mysql_type'=>'DATETIME',
'not null'= > TRUE,
),
'ticket'=>数组(
'type'=>'int',
'unsigned'=& $ b'not null'=> TRUE,
),
'ticket_code'=>数组(
'type'=>'varchar',
'length' => 32,
'not null'=> TRUE,
'default'=>'' ,
),
)主键'=>数组('nid','day','ticket_code'),
);

但是我收到以下错误:

  Field museums_tickets.day:no mysql类型为datetime的Schema类型。 
museums_tickets.day:没有类型的Schema类型datetime。
Field museums_tickets.day:no类型为datetime的Schema类型。

同样适用于我使用

 'type'=> 'datetime:normal',

我想知道如何解决这个问题。
我不想将日期存储为时间戳,因为另一个人写了很多代码,显然我不想重写所有的代码。
我已经看过 drupal 7自定义模式错误日期时间,但是答案不行。
也许我做错了,但我没有找到什么。



提前谢谢。

解决方案

如果您查看Date模块的模式,您将会发现类似于

 'day'=>数组(
'type'=>'datetime',
'mysql_type'=>'datetime',

实际上,Clive的答案是我先选择的答案,但后来给了我的Views模块的问题。



日期模块的这个实现保存我的一天


I'm writing a new Drupal 7 module (Drupal 7.10, Date 7.x-2.0-rc1 installed, Schema 7.x-1.0-beta3 installed) i defined a table in mymodule.install:

$schema['museums_tickets']= array(
    'fields' => array(
        'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
    ),
    'day' => array(
        'type' => 'datetime', 
        'mysql_type' => 'DATETIME',
        'not null' => TRUE,
    ),
    'tickets' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        ),
    'ticket_code' => array(
            'type' => 'varchar',
            'length' => 32,
            'not null' => TRUE, 
            'default' => '',
        ),
    ),
    'primary key' => array('nid', 'day','ticket_code'),
);

but i obtain the following errors:

Field museums_tickets.day: no Schema type for mysql type datetime.
museums_tickets.day: no type for Schema type datetime.
Field museums_tickets.day: no Schema type for type datetime. 

The same applies if i use

'type' => 'datetime:normal',

I would like to know how to solve this problem. I don't want to store dates as timestamp, since another person wrote a lot of code and obviously i don't want to rewrite all. I already looked at drupal 7 custom schema error datetime but the answer doesn't work. Maybe i'm doing something wrong, but i don't find what.

Thank you in advance.

解决方案

If you look in the schema of the Date module you will find something like

'day' => array(
    'type' => 'datetime',
    'mysql_type' => 'datetime',
)

Actually the answer of Clive was the one i picked first but later gave me problems with the Views module.

This implementation of the Date module save my day

这篇关于Drupal 7模式中的日期时间类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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