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

查看:187
本文介绍了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?

  • hook_menu()在Drupal 7中没有$ 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".它需要一个返回"true"或"false"的函数名.它默认为'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'.

下面的代码行更好吗?

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;
}

似乎您并没有真正了解

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天全站免登陆