繁体   English   中英

hook_menu在自定义模块上不起作用

[英]hook_menu not working on a custom module

也许我很明显,但是一个简单的自定义Hello world模块无法正常工作。 我花了几天的时间来解决这个问题,但没有任何进展。

hello_world.info

name = Hello World
description = "This module is to test hello world"
core = 7.x

hello_world.module

<?php
/**
* Implements hook_init()
*/

function oulta_hello_world_init() {
  drupal_set_message("From Hello World Module");
}

/**
* Implements hook_menu()
*/

function hello_world_menu() {
  $items['hello_world'] = array(
  'title' => 'Just saying hello world',
  'page callback' => 'hello_world_pg',
  'access callback' => TRUE,
  'type' => MENU_CALLBACK,
  );
  return $items;
}

function hello_world_pg() {
  drupal_set_message("Hello World page called");
  return 'Hello world!';
}

我正在尝试访问位于localhost / mysite / hello_world /的页面

.module和.info文件的路径是htdocs / mysite / sites / all / modules / custom

由于hook_menu是开发的基础,所以我陷入了困境。 请帮忙。

顺便说一句,hook_menu是否有替代方法来渲染页面?

提前致谢。

将您的代码更改为

function hello_world_menu() {
  $items = array(); // define the $items array

  $items['hello_world'] = array(
  'title' => 'Just saying hello world',
  'page callback' => 'hello_world_pg',
  'access callback' => TRUE,
  'type' => MENU_CALLBACK,
  );
  return $items;
}

然后刷新您的网站缓存。

在尝试了无数解决方案后,它仍然无法正常工作。 我得出的结论是,这是数据库损坏的结果。 加载了较旧的数据库,Voila一切开始正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM