Drupal问题,如何创建快速内容模块?

时间:2021-04-08 21:11:45

Hi I need to create a module in drupal to display some data, not being a drupal developer and after reading a couple of tutorials, i cant seem to display anything.

嗨我需要在drupal中创建一个模块来显示一些数据,而不是一个drupal开发人员,在阅读了几个教程后,我似乎无法显示任何内容。

I have the next code:

我有下一个代码:

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

When i enter /listado i get a Access denied You are not authorized to access this page.

当我输入/ listado时,我获得访问被拒绝您无权访问此页面。

Any idea what im doing wrong? If i go to the admin->module->permissions, i have checked the permision for all roles to access hellowold content.

知道我做错了什么?如果我转到admin-> module-> permissions,我已检查所有角色的权限以访问hellowold内容。

Ty!

4 个解决方案

#1


From the way that your menu array is structured in helloworld_menu(), I'm assuming that this is Drupal 6. If so, you need to rename 'access' to 'access arguments'. See http://api.drupal.org/api/function/hook_menu/6.

从您在helloworld_menu()中构造菜单数组的方式来看,我假设这是Drupal 6.如果是这样,您需要将'access'重命名为'access arguments'。见http://api.drupal.org/api/function/hook_menu/6。

The Drupal API documentation also includes a heavily-commented page_example.module that's doing basically what you're doing here, which you might want to check out: http://api.drupal.org/api/file/developer/examples/page_example.module/6/source

Drupal API文档还包括一个评论很重的page_example.module,它基本上就是你在这里做的,你可能想要查看它:http://api.drupal.org/api/file/developer/examples/page_example .module / 6 /源

Hope that helps!

希望有所帮助!

Oh. And don't forget to clear your cache afterwards from the "Clear cache" button on Administer >> Site configuration >> Performance.

哦。并且不要忘记之后从管理>>站点配置>>性能上的“清除缓存”按钮清除缓存。

#2


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

Note that , MENU_NORMAL_ITEM being the default value for type, you do not need to specify it.

请注意,MENU_NORMAL_ITEM是type的默认值,您无需指定它。

Also, as our esteemed webchick just said

此外,正如我们尊敬的webchick所说

#3


It seems you are using a mix of Drupal 5 (array contents) and Drupal 6 (no $may_cache, $items indexed by path) syntaxes for hook_menu.

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

If you are using Drupal 6, this should look like:

如果你使用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;
}
?>

Note that, MENU_NORMAL_ITEM being the default value for 'type', you do not need to specify it.

请注意,MENU_NORMAL_ITEM是'type'的默认值,您无需指定它。

Also, as our esteemed webchick just said, you can find a detailed explanation on the page she points to.

此外,正如我们尊敬的webchick所说,你可以在她指向的页面上找到详细的解释。

#4


just FYI , above link moved to

仅供参考,以上链接移至

http://api.drupal.org/api/examples/page_example--page_example.module/6

#1


From the way that your menu array is structured in helloworld_menu(), I'm assuming that this is Drupal 6. If so, you need to rename 'access' to 'access arguments'. See http://api.drupal.org/api/function/hook_menu/6.

从您在helloworld_menu()中构造菜单数组的方式来看,我假设这是Drupal 6.如果是这样,您需要将'access'重命名为'access arguments'。见http://api.drupal.org/api/function/hook_menu/6。

The Drupal API documentation also includes a heavily-commented page_example.module that's doing basically what you're doing here, which you might want to check out: http://api.drupal.org/api/file/developer/examples/page_example.module/6/source

Drupal API文档还包括一个评论很重的page_example.module,它基本上就是你在这里做的,你可能想要查看它:http://api.drupal.org/api/file/developer/examples/page_example .module / 6 /源

Hope that helps!

希望有所帮助!

Oh. And don't forget to clear your cache afterwards from the "Clear cache" button on Administer >> Site configuration >> Performance.

哦。并且不要忘记之后从管理>>站点配置>>性能上的“清除缓存”按钮清除缓存。

#2


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

Note that , MENU_NORMAL_ITEM being the default value for type, you do not need to specify it.

请注意,MENU_NORMAL_ITEM是type的默认值,您无需指定它。

Also, as our esteemed webchick just said

此外,正如我们尊敬的webchick所说

#3


It seems you are using a mix of Drupal 5 (array contents) and Drupal 6 (no $may_cache, $items indexed by path) syntaxes for hook_menu.

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

If you are using Drupal 6, this should look like:

如果你使用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;
}
?>

Note that, MENU_NORMAL_ITEM being the default value for 'type', you do not need to specify it.

请注意,MENU_NORMAL_ITEM是'type'的默认值,您无需指定它。

Also, as our esteemed webchick just said, you can find a detailed explanation on the page she points to.

此外,正如我们尊敬的webchick所说,你可以在她指向的页面上找到详细的解释。

#4


just FYI , above link moved to

仅供参考,以上链接移至

http://api.drupal.org/api/examples/page_example--page_example.module/6