Drupal 7中的模块路径是什么? [英] What is the path of my module in Drupal 7?

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

问题描述

这是我第一次使用Drupal 7,我写了一个回声测试的测试模块,菜单中的路径是test。



我正在尝试访问localhost / drupal / test或localhost / drupal / admin / test,它找不到它,我看到404或管理页面。



什么是这里的问题吗?






这是代码,它不工作

 <?php 
/ * $ Id $ * /

/ **
* @file
*非常简单的DRUPAL模块
* /

/ **
*执行hook_help()。
* /
函数hello_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 ...';
}
}

/ **
*执行hook_menu()。
* /
函数hello_world_menu($ may_cache){
$ items = array();

if($ may_cache){
}
else {
$ items [] = array(
'path'=>'hello' // drupal path example.com/?q=hello
'title'=>'Hello world page ...',//页面标题
'callback'=>'hello_world_page',/ / callback function name
'access'=> TRUE,//每个用户都可以查看生成的页面
'type'=> MENU_CALLBACK //将菜单项的类型定义为回调
) ;
}

return $ items;
}


/ **
*生成页面的功能(这产生任何内容 - 您只需要自己的代码...)
* /
function hello_world_page(){
return'< p> Hello world!< / p>';
}
?>


解决方案

如果我正确得到你,


  1. 你写了一个 hook_menu()你创建了一个菜单路径测试(说 $ item ['test'] )并写了一个页面回调函数。


  2. 在页面回调函数,你说回声测试。


如果是这种情况,你只需要清除缓存即可。 Drupal需要注册菜单项。在编写任何菜单挂钩实现后,您应该清除缓存的数据,然后重试。


This is my first time with Drupal 7, i wrote a test module that echo "test" , and in the menu the path is "test".

When i'm trying to access localhost/drupal/test OR localhost/drupal/admin/test it can't find it, and i see 404 or admin page.

What is the problem here?


this is the code, and its doesnt work

<?php
/* $Id$ */

/**
* @file
* Very simple DRUPAL module
*/

/**
* Implementation of hook_help().
*/
function hello_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...';
  }
}

/**
* Implementation of hook_menu().
*/
function hello_world_menu($may_cache) {
  $items = array();

  if ($may_cache) {
  }
  else {
    $items[] = array(
      'path' => 'hello', // drupal path example.com/?q=hello
      'title' => 'Hello world page...', // page title
      'callback' => 'hello_world_page', // callback function name
      'access' => TRUE, // every user can look at generated page
      'type' => MENU_CALLBACK // define type of menu item as callback
    );
  }

  return $items;
}


/**
* Function which generate page (this generate any content - you need only your own code...)
*/
function hello_world_page() {
  return '<p>Hello world!</p>';
}
?>

解决方案

If I am getting you correctly,

  1. you wrote a hook_menu() where you created a menu path test(say $item['test']) and wrote a page callback function.

  2. In the page callback function, you say echo test.

If this is the scenario, you just need to clear your cache. Drupal needs to register the menu item. After writing any menu hook implementation, you should clear your cached data and then try again.

这篇关于Drupal 7中的模块路径是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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