【问题标题】:What is the path of my module in Drupal 7?我的模块在 Drupal 7 中的路径是什么?
【发布时间】:2011-09-22 06:28:47
【问题描述】:

这是我第一次使用 Drupal 7,我写了一个回显“test”的测试模块,在菜单中路径是“test”。

当我尝试访问 localhost/drupal/test 或 localhost/drupal/admin/test 时找不到它,我看到 404 或管理页面。

这里有什么问题?


这是代码,它不起作用

<?php
/* $Id$ */

/**
* @file
* Very simple DRUPAL module
*/

/**
* Implementation of hook_help().
*/
function hello_world_help($section) {
  switch ($section) {
    case 'admin/help#hello_world':
      $output = '<p>Hello world help...</p>';
      return $output;
    case 'admin/modules#description':
      return 'Hello world module description...';
  }
}

/**
* Implementation of hook_menu().
*/
function hello_world_menu($may_cache) {
  $items = array();

  if ($may_cache) {
  }
  else {
    $items[] = array(
      'path' => 'hello', // drupal path example.com/?q=hello
      'title' => 'Hello world page...', // page title
      'callback' => 'hello_world_page', // callback function name
      'access' => TRUE, // every user can look at generated page
      'type' => MENU_CALLBACK // define type of menu item as callback
    );
  }

  return $items;
}


/**
* Function which generate page (this generate any content - you need only your own code...)
*/
function hello_world_page() {
  return '<p>Hello world!</p>';
}
?>

【问题讨论】:

标签: drupal


【解决方案1】:

使用drupal_get_path() 获取模块或主题的路径。如果您的模块名称是“mymodule”,那么您只需调用以下代码即可获取路径。

drupal_get_path('module', 'mymodule');

编辑

再次阅读您的问题让我意识到您正在询问您模块的 URL。能否请您发布您在模块的 hook_menu() 中获得的代码?

【讨论】:

  • 我来到这里是因为帖子的标题,虽然这不是 OP 想要的,但它回答了我的问题 :)
【解决方案2】:

如果我没听错的话,

  1. 你写了一个hook_menu(),在那里你创建了一个菜单路径测试(比如$item['test'])并写了一个页面回调函数。

  2. 在页面回调函数中,你说回声测试。

如果是这种情况,您只需要清除缓存。 Drupal 需要注册菜单项。编写完任何菜单挂钩实现后,您应该清除缓存数据,然后重试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多