tags:

views:

382

answers:

3

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.

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.

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.

Ty!

+5  A: 

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.

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

Hope that helps!

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

webchick
A: 

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.

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

<?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.

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

FGM

related questions