Drupal 7 示例模块,找不到页面,为什么? [英] Drupal 7 example module, page not found, why?

查看:29
本文介绍了Drupal 7 示例模块,找不到页面,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简单的测试模块示例,2 个文件,test.module、test.info,并在 drupal 7 模块中启用它们.

I wrote a simple test module example, 2 files, test.module, test.info, and enabled them in drupal 7 modules.

我清除了所有缓存,但当我尝试访问 localhost/drupal/hello 时,仍然找不到 drupal 404 页面,这是为什么?

I cleared all the cache, and still when i'm trying to go to localhost/drupal/hello , i get drupal 404 page not found, why is that?

这是我的代码:

<?php

function test_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...';
  }
}

function test_world_menu($may_cache) {
  $items = array();

  if ($may_cache) {
  }
  else {
    $items['hello'] = array(
      'title' => 'Hello world page...', 
      'callback' => 'test_world_page', 
      'access' => TRUE, 
      'type' => MENU_CALLBACK 
    );
  }

  return $items;
}

function test_world_page() {
  return '<p>Hello world!</p>';
}

推荐答案

您已经发布了几乎相同的问题 一次两次 之前.你为什么不更新原始的而不是发布新的?

You have posted almost the same question once and twice before. Why don't you update the original one instead of posting new ones?

  • Drupal 7 中的 hook_menu() 没有 $may_cache 参数.您应该删除它.但是,它不应该解决您的问题,因为它未设置且为假.因此,仍应填充 $items.

  • The hook_menu() does not have the $may_cache argument in Drupal 7. You should remove it. However, it should not solve your problem as it is unset and false. Thus, the $items should still be populated.

正如 jprofitt 所说,您应该将回调"更改为页面回调"是正确的.

It is correct, as jprofitt says, that you should change 'callback' to 'page callback'.

没有访问"这样的东西,但有访问回调"和访问参数".您很可能正在寻找访问回调".但是,您不能将其设置为true".它需要一个返回真"或假"的函数名.它默认为user_access",因此您应该保持这种状态.但是,您可能希望将访问参数"设置为访问内容"之类的内容.

There is no such thing as 'access', but there is 'access callback' and 'access arguments'. You are most likely looking for 'access callback'. However, you can't just set it to 'true'. It expects a function name which returns either 'true' or 'false'. It defaults to 'user_access', so you should just leave it that way. However, you might want to set 'access arguments' to something like 'access content'.

下面这段代码效果更好吗?

Does the following piece of code work better?

function test_world_menu() {

  $items = array();

  $items['hello'] = array(
    'title' => 'Hello World!', 
    'page callback' => 'test_world_page', 
    'access arguments' => array('access content'), 
    'type' => MENU_CALLBACK 
    );

  return $items;
}

看来你还没有真正看过文档.我可能错了.但是,当您想了解某项工作的基本原理时,api.drupal.org 上的文档总是一个好的开始.

It seems that you haven't really had a look at the documentation. I might be wrong. However, the documentation at api.drupal.org is always a good start to look when you want to learn the basics of how something work.

这篇关于Drupal 7 示例模块,找不到页面,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆