在 drupal 5 中创建 hello-world 模块时遇到问题

发布于 2024-09-09 09:22:24 字数 921 浏览 3 评论 0原文

以下是我创建 mudule 的步骤:

  1. groups 中的 sites/all/modules 下创建一个目录
  2. 在上述目录 groups,创建两个文件 groups.modulegroups.info

groups.info 的内容:

; $Id: groups.info,v 1.3 2006/11/21 20:55:36 dries Exp $
name = groups
description = Test Groups Listings.
package = "test groups"

version = "5.10"
project = "ed_groups"
datestamp = "1218672307"

groups.module 的内容:

<?php
function groups_menu($may_cache)
{
    $items = array();
    $items[] = array(
        'path' => 'test_menu',
        'type' => MENU_CALLBACK,
        'callback' => 'groups_list',
        'title' => t('All Group Listing')
    );
}

function groups_list()
{
    return 'helloworld';
}

我在访问 site.com/test_menu 时出现了 oops(404) 页面,

您能发现上面的问题吗?

Here're the steps I did to create an mudule:

  1. create a directory groups under sites/all/modules
  2. in the above directory groups, create two files groups.module and groups.info

The content of groups.info:

; $Id: groups.info,v 1.3 2006/11/21 20:55:36 dries Exp $
name = groups
description = Test Groups Listings.
package = "test groups"

version = "5.10"
project = "ed_groups"
datestamp = "1218672307"

The content of groups.module:

<?php
function groups_menu($may_cache)
{
    $items = array();
    $items[] = array(
        'path' => 'test_menu',
        'type' => MENU_CALLBACK,
        'callback' => 'groups_list',
        'title' => t('All Group Listing')
    );
}

function groups_list()
{
    return 'helloworld';
}

I got an oops(404) page when visiting site.com/test_menu

Can you spot what's wrong above?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缪败 2024-09-16 09:22:24

看来您的问题是您没有在 hook_menu 中返回 $items。

应该是:

function groups_menu($may_cache) {
    $items = array();
    $items[] = array(
        'path' => 'test_menu',
        'type' => MENU_CALLBACK,
        'callback' => 'groups_list',
        'title' => t('All Group Listing')
    );
    return $items;
}

执行此操作后请记住清除缓存,因为 Drupal 会缓存菜单系统。

It looks like your problem is that you don't return $items in your hook_menu.

It should be:

function groups_menu($may_cache) {
    $items = array();
    $items[] = array(
        'path' => 'test_menu',
        'type' => MENU_CALLBACK,
        'callback' => 'groups_list',
        'title' => t('All Group Listing')
    );
    return $items;
}

Remember to clear the cache after you do this, as Drupal caches the menu system.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文