php - 德鲁帕尔 "You are not authorized to access this page."

标签 php drupal drupal-7 drupal-modules

我刚刚开始使用 drupal,所以如果这是一个非常愚蠢的问题,我深表歉意。我编写了以下模块,但每次尝试访问它时,转到 url (http://localhost:8888/drupal/doodil_viral_signup) 时,我都会收到一条访问被拒绝的消息。我尝试过重建权限并禁用和重新启用该模块,但似乎不起作用。

<?php
// $Id$
/**
* @file
* A module to encourage users to sign up.
* This module allows users to sign up to register for the site, and invite their friends to do the same.
*/

/**
* Implements hook_help().
*/
function doodil_viral_signup_help($path, $arg) {
  if ($path == 'admin/help#first') {
    return t('This module allows users to sign up to register for the site, and invite their friends to do the same.');
  }
}

/**
* Implements hook_menu().
*/
function doodil_viral_signup_menu($may_cache = true) {
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'doodil_viral_signup',
      'title' => t('Doodil Signup'),
      'callback' => 'doodil_viral_signup_page',
      'access' => TRUE,
      'type' => MENU_CALLBACK,
    );
  }
  return $items;
}

function doodil_viral_signup_page() {
  return drupal_get_form('doodil_viral_signup_page_form');
}

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

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

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

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

function doodil_viral_signup_page_form_submit($form_id, $form_values) {
  $message = 'You have submitted the following information <pre>'.print_r($form_values).'</pre>';
  drupal_set_message(t($message));
}

谁能告诉我如何解决这个问题?

提前致谢!

最佳答案

按照 loganfsmyth 的建议执行除 hook_menu() 之外的所有操作,应该如下所示:

function doodil_viral_signup_menu() {
  $items = array();
  $items['doodil_viral_signup'] = array(
    'title' => 'Doodil Signup',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('doodil_viral_signup_page_form'),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  return $items;
}

并删除doodil_viral_signup_page()函数。

编辑

这刚刚在我的机器上测试过,运行完美。如果它在您的机器上不起作用,那么问题不在于该模块。

function doodil_viral_signup_help($path, $arg) {
  if ($path == 'admin/help#first') {
    return t('This module allows users to sign up to register for the site,
    and invite their friends to do the same.');
  }
}

function doodil_viral_signup_menu() {
  $items = array();
  $items['doodil_viral_signup'] = array(
    'title' => 'Doodil Signup',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('doodil_viral_signup_page_form'),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK
  );
  return $items;
}

function doodil_viral_signup_page_form($form, &$form_state) {
  $form['first_name'] = array(
    '#type' => 'textfield',
    '#title' => t('First Name')
  );
  $form['last_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Last Name')
  );
  $form['email_address'] = array(
    '#type' => 'textfield',
    '#title' => t('Email Address')
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Sign Me Up')
  );
  return $form;
}

function doodil_viral_signup_page_form_submit($form, $form_state) {
  $message = t('Your submitted information <pre>!info</pre>', array(
    '!info' => print_r($form_state['values'], TRUE)
  ));
  drupal_set_message($message);
}

关于php - 德鲁帕尔 "You are not authorized to access this page.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9436565/

相关文章:

javascript - WordPress JSON API - 请求 header 错误

php - Drupal - 无法从 db_query 获得结果

css - 使用 css 注入(inject)器的 drupal home 的大图像

drupal-7 - 如何显示某个节点的最近 View =每个用户的类型

php - Linux 上意外的 T_STRING

php - 如何设置特定用户对后端 Joomla 2.5.4 中特定模块的访问权限?

php - Libreoffice --headless 拒绝转换,除非 root,无法从 PHP 脚本运行

php - Drupal负载平衡

javascript - drupal 7服务3.0使用图像创建节点

mysql - 将嵌套选择查询转换为 Drupal 7 db_select?