You are here

创建.install文件

g089h515r806 的头像
Submitted by g089h515r806 on 星期二, 2009-08-11 09:05

老葛的Drupal培训班 Think in Drupal

你将需要在你的数据库表中存储一些信息。首先,你需要节点的ID,这样你就可以引用node_revisions表中的对应节点了,node_revisions表存储了节点的标题和主体。其次,你需要存储节点的修订本ID,这样你的模块就可以使用Drupal内置的修订本控制了。当然,你还需要存储笑话妙语。由于你已经知道了数据库的模式,让我们继续,创建joke.install文件并将其放到目录sites/all/modules/custom/joke下面。关于创建安装文件的更多信息,可参看第2章。
 
<?php
// $Id$
 
/**
 * Implementation of hook_install().
 */
function joke_install() {
    drupal_install_schema('joke');
}
 
/**
 * Implementation of hook_uninstall().
 */
function joke_uninstall() {
    drupal_uninstall_schema('joke');
}
 
/**
 * Implementation of hook_schema().
 */
function joke_schema() {
    $schema['joke'] = array(
        'description' => t("Stores punch lines for nodes of type 'joke'."),
        'fields' => array(
            'nid' => array(
                'type' => 'int',
                'unsigned' => TRUE,
                'not null' => TRUE,
                'default' => 0,
                'description' => t("The joke's {node}.nid."),
            ),
            'vid' => array(
                'type' => 'int',
                'unsigned' => TRUE,
                'not null' => TRUE,
                'default' => 0,
                'description' => t("The joke's {node_revisions}.vid."),
            ),
            'punchline' => array(
                'type' => 'text',
                'not null' => TRUE,
                'description' => t('Text of the punchline.'),
            ),
        ),
        'primary key' => array('nid', 'vid'),
        'unique keys' => array(
            'vid' => array('vid')
        ),
        'indexes' => array(
            'nid' => array('nid')
        ),
    );
 
    return $schema;
}
 

Drupal版本: