Drupal 7 为什么赢了';这个模式在Drupal7中不能安装文件吗?

Drupal 7 为什么赢了';这个模式在Drupal7中不能安装文件吗?,drupal-7,drupal-modules,database-schema,Drupal 7,Drupal Modules,Database Schema,我在文件“doodil.install”中定义了以下模式,作为我正在编写的自定义模块的一部分。然而,每次我在Drupal中启用模块时,我都会看到一个白色的死亡屏幕。doodil.install的代码如下所示: <?php function doodil_schema() { $schema['doodil_user'] = array( 'description' => t('The table containing users who have signed u

我在文件“doodil.install”中定义了以下模式,作为我正在编写的自定义模块的一部分。然而,每次我在Drupal中启用模块时,我都会看到一个白色的死亡屏幕。doodil.install的代码如下所示:

<?php
function doodil_schema() {
    $schema['doodil_user'] = array(
      'description' => t('The table containing users who have signed up for the chance to register.'),
      'fields' => array(
        'id' => array(
        'description' => t('Primary Key ID'),
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'email_address' => array(
        'description' => t('User\'s Email Address'),
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'first_name' => array(
        'description' => t('User\'s First Name'),
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'last_name' => array(
        'description' => t('User\'s Last Name'),
        'type' => 'varchar',
        'length' => 255,
      ),
      'user_hash' => array(
        'description' => t('A unique hash string to ID the User'),
        'type' => 'varchar',
        'length' => 100,
        'not null' => TRUE,
      ),
      'active' => array(
        'description' => t('Whether the account has been activated'),
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'successful_invites' => array(
        'description' => t('The number of invites responded to'),
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      )
    ),
    'primary key' => array( 'id' ),
  );

  // Return the Table Schema
  return $schema;
}

你发布的代码对我来说非常好。假设这是安装文件的完整代码,我完全确定问题出在别处。很可能是模块的其他文件中的语法错误。您的.install代码100%正常。

问题在模块文件的第127行。drupal_write_record('doodil_user',array('email_address'=>$form_args['values']['email_address'],'first_name'=>$form_args['values']['last_name'],'user_hash'=>$user_hash,);drupal_write_记录的第二个参数应通过引用传递,但不能通过引用传递常量。因此,解决方法是在这一行之前声明一个数组变量,然后将其传递给drupal_write_record。类似于:$param=array($email_address'=>$form_args['values']['email_address'],'first_name'=>$form_args['values'['first_name'],'user_hash'=>user_hash,);drupal_write_记录('doodil_user',$param);似乎无法将您的评论标记为正确,但可以!我没有意识到必须在函数params之外声明数组。你的修复成功了,谢谢!
<?php
// $Id$
/**
* @file
* A module for encouraging users to sign up to Doodil, the hottest social
* network on the web.
*
* This module encourages users to invite their friends to sign up to Doodil
*/

define('USER_SIGNUP_CONFIRM_EMAIL',
'Hi !firstname,

You\'re just one step away from being able to invite your friends to Doodil - the hottest Social Network on the web!  Just click the link below and you\'ll be all set to earn some invite points.

!confirmlink

See you soon!

Team Doodil');

/**
* Implements hook_help().
*/
function doodil_help($path, $arg) {
  if ($path == 'admin/help#doodil') {
    return t('A module to encourage users to invite their friends to sign up to Doodil.');
  }
}

/**
* Implements hook_menu().
*/
function doodil_menu() {
  // Create an Array of Menu Items
  $items = array();

  // Add the Initial "Sign Up" Item
  $items['doodil/signup'] = array(
    'title' => 'Sign up to Doodil',
    'description' => 'Sign up to Doodil and invite your friends',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('doodil_signup_form'),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );

  // Add the Sign Up from Invitation Item
  $items['doodil/signup/%'] = array(
    'title' => 'Sign up to Doodil',
    'description' => 'Sign up to Doodil and invite your friends',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('doodil_signup_form', 1),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );

  // Add the Invitation Page
  $items['doodil/invite/%'] = array(
    'title' => 'Invite your Friends to Doodil',
    'description' => 'Invite your Friends to join Doodil',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('doodil_invite_form', 1),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );

  // Return the Items Array
  return $items;
}

function doodil_signup_form($form, &$form_args, $uhash = null, $fullsize = TRUE) {
  // Determine the Size of the Form (Full Size for Page, Small for Block)
  if ($fullsize) {
    $width = '100';
  } else {
    $width = '20';
  }

  // [input text] First Name
  $form['first_name'] = array(
    '#type' => 'textfield',
    '#title' => t('First Name'),
    '#size' => $width,
  );

  // [input text] Last Name
  $form['last_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Last Name'),
    '#size' => $width,
  );

  // [input text] Email Address
  $form['email_address'] = array(
    '#type' => 'textfield',
    '#title' => t('Email Address'),
    '#size' => $width,
  );

  // [input hidden] User Hash
  $form['user_hash'] = array(
    '#type' => 'hidden',
    '#value' => $uhash,
  );

  // [input submit] Sign Me Up
  $form['submit'] = array(
    '#type' => 'submit',
    '#title' => t('Sign Me Up'),
    '#value' => t('Sign Me Up'),
  );
  return $form;
}

function doodil_signup_form_submit($form, $form_args) {
  // Get the Base URL
  global $base_url;

  // Create a Unique Hash Key
  $user_hash = substr(md5($form_args['values']['email_address'].microtime(true)), 0, 15);

  // Create a Confirm User Link
  $confirm_link = $base_url.'/doodil/confirm_signup/'.$user_hash;

  // Insert the User into the Table
  drupal_write_record('doodil_user', array(
    'email_address' => $form_args['values']['email_address'],
    'first_name' => $form_args['values']['first_name'],
    'last_name' => $form_args['values']['last_name'],
    'user_hash' => $user_hash,
  ));

  // Build an "Account Array"
  $account = array(
    'first_name' => $form_args['values']['first_name'],
    'last_name' => $form_args['values']['last_name'],
    'email_address' => $form_args['values']['email_address'],
    'confirm_link' => $confirm_link,
  );

  // Send the Email
  drupal_mail(
    'doodil',
    'signup_confirm',
    $account['email_address'],
    language_default(),
    $account,
    variable_get('site_mail', NULL),
    TRUE
  );

  // Do some Stuff here like email user and add to temp users table?
  $message = t('A confirmation email has been sent to !email.',
    array(
      '!email' => $form_args['values']['email_address'],
      '!uhash' => $form_args['values']['user_hash'],
    ));

  // Send a Message
  drupal_set_message($message);
}

function doodil_invite_form($form, &$form_args, $uhash) {
  // Make the Form Element an Array
  $form['email_address']['#tree'] = true;

  // Loop through and add 10 Fields
  for ($i = 1; $i <= 10; $i++) {
    $form['email_address'][$i] = array(
      '#type' => 'textfield',
      '#title' => t('Friend !number\'s Email Address', array('!number' => $i)),
    );
  }

  // [input submit] Sign Me Up
  $form['submit'] = array(
    '#type' => 'submit',
    '#title' => t('Invite Friends'),
    '#value' => t('Invite Friends'),
  );

  // Return the Form
  return $form;
}

/**
* Implements hook_block_info().
*/
function doodil_block_info() {
  // Create an Array of Blocks
  $blocks = array();

  // Add the Sign Up Block
  $blocks['signup_form'] = array(
    'info' => t('Doodil Signup Form.'),
    'cache' => DRUPAL_NO_CACHE,
  );

  // Return the Blocks
  return $blocks;
}

/**
* Implements hook_block_view().
*/
function doodil_block_view($block_name = '') {
  // Figure out which block to show
  switch($block_name) {
    case('signup_form'):
      $block = array(
        'subject' => null,
        'content' => drupal_get_form('doodil_signup_form', null, FALSE),
      );
    break;
  }

  // Return the Block View
  return $block;
}

/**
* Implements hook_mail().
*/
function doodil_mail($key, &$message, $params) {
  switch($key) {
    case('signup_confirm'):
      //$account = (object) $params;
      $subject = t('Welcome to Doodil');
      $body = USER_SIGNUP_CONFIRM_EMAIL;

      $message['to'] = $params['email_address'];
      $message['subject'] = $subject;
      $message['body'][] = t(USER_SIGNUP_CONFIRM_EMAIL, array(
    '!firstname' => $params['first_name'],
    '!confirmlink' => $params['confirm_link']
      ));
    break;
  }

  // Return the Message Array
  return $message;
}