2009-01-24 57 views
1

您好我需要在drupal中创建一个模块来显示一些数据,而不是一个Drupal开发人员,并阅读了几个教程后,我似乎无法显示任何东西。Drupal问题,如何创建一个快速内容模块?

我有下面的代码:

<?php 
function helloworld_perm() { 
    return array('access helloworld content'); 
} 

function helloworld_listado(){ 
return "yea"; 
} 

function helloworld_menu(){ 
    $items = array(); 
    $items["listado"] = array(
     'title' => t('Listado de empresas'), 
     'callback' => 'helloworld_listado', 
     'access' => array('access helloworld content'), 
     'type' => MENU_NORMAL_ITEM 
    ); 
    return $items; 
} 

当我输入/ listado我得到一个拒绝访问 您无权访问此页面。

任何想法即时做错了什么? 如果我转到管理 - >模块 - >权限,我检查了所有角色的访问权限以访问hellowold内容。

Ty!

回答

6

从你的菜单数组结构在helloworld_menu()中,我假设这是Drupal 6.如果是这样,你需要重命名'访问'为'访问参数'。见http://api.drupal.org/api/function/hook_menu/6

Drupal的API文档还包括一重评论page_example.module是在做基本上你在这里做什么,你可能想看看:http://api.drupal.org/api/file/developer/examples/page_example.module/6/source

希望帮助!

哦。并且不要忘记从Administer >> Site configuration >> Performance中的“清除缓存”按钮之后清除缓存。

0

看起来你正在为hook_menu使用混合的Drupal 5(数组内容)和Drupal 6(没有$ may_cache,路径索引的项目)语法。

如果您正在使用的Drupal 6,这应该是这样的:

<?php 
function helloworld_perm() { 
    return array('access helloworld content'); 
} 

function helloworld_listado(){ 
return "yea"; 
} 

function helloworld_menu(){ 
    $items = array(); 
    $items["listado"] = array(
     'title'   => t('Listado de empresas'), 
     'page callback' => 'helloworld_listado', 
     'access arguments' => array('access helloworld content'), 
     'type'    => MENU_NORMAL_ITEM, 
    ); 
    return $items; 
} 
?> 

需要注意的是,MENU_NORMAL_ITEM是为“类型”的默认值,你并不需要指定它。

此外,正如我们尊敬的网站刚刚说的,您可以在她指向的页面上找到详细的解释。

1
=> t('Listado de empresas'), 
    'page callback' => 'helloworld_listado', 
    'access arguments' => array('access helloworld content'), 
    'type'    => MENU_NORMAL_ITEM, 
); 
return $items; 
} 

需要注意的是,MENU_NORMAL_ITEM是用于type的默认值,你并不需要指定它。

此外,正如我们尊敬的网站刚刚说的