0

我是drupal的新手,目前正在学习drupal 7。

我指的是 drupal 7 的书

我试图创建我的第一个自定义模块

在书中提到您可以在以下目录之一中创建模块

1)/站点/所有/模块

2) /sites/default/modules

我的模块名称是第一个

我在 /sites/default/modules/first 中创建了我的模块

在这个目录中有两个文件

1)第一信息

2) first.module

第一个 .info 文件的内容是

;$Id$
name = First
description = A first module.
package = Drupal 7 Development
core = 7.x
files[] = first.module
;dependencies[] = autoload
;php = 5.4

fisrt.module 文件的内容是

<?php
// $Id$
/**
* @file
* A module exemplifying Drupal coding practices and APIs.
*
* This module provides a block that lists all of the
* installed modules. It illustrates coding standards,
* practices, and API use for Drupal 7.
*/
/**
* Implements hook_help().
*/

function first_help($path, $arg) {
if ($path == 'admin/help#first') {
return t('A demonstration module.');
}
}
?>

当我尝试检查模块列表时,我看不到我创建的模块

我已经厌倦了清除缓存并检查仍然没有显示

谁能告诉我哪里错了。

提前致谢

4

4 回答 4

3

模块位置
大多数人选择将模块放在/sites/all/modulesor/sites/domain.com/modules文件夹中(而不是sites/default...)。对于最常见的 Drupal 安装,您应该将其放在sites/all/modules.

信息文件 信息文件
中仅需要名称、描述和核心。首先删除除这些值之外的所有内容。

name = First
description = A first module.
core = 7.x

有关详细信息,请参阅编写模块 .info 文件 (Drupal 7.x)

一些注意事项:

  • “package”属性“应该只被大型多模块包使用”
  • 你不需要.module在“files”属性中声明你的模块文件。
  • 暂时删除注释掉的行。如果您的模块确实需要 PHP 5.4,您可以在完成故障排除后将其重新添加。
于 2013-03-01T11:33:42.683 回答
1

我通过启动我的 .info 文件解决了这个问题

name = First

并使我的文件编码:

无 BOM 的 UTF-8

使用 Notpade++ 时你会发现它很容易

于 2013-12-02T09:37:30.680 回答
0
function test_example_help($path, $arg){
switch ($path) {
case "admin/help#test_example":
return '<p>' . t("test module to see how it works and shows") . '</p>';
break;
}

使用 switch 语句尝试以下示例,看看它是否有效

于 2013-07-25T10:05:16.440 回答
0

尝试取出标记 php 代码结尾的?>。这样做是为了防止空格破坏 HTTP 标头。

于 2013-11-18T13:19:33.720 回答