Please save me! I installed a new Drupal 6.22 last week. I wrote a really simple example of hook_menu(), but it didn't work totally. I am really confused, hope someone help me please.

This is test.info

; $Id$
name = Test
description = Allows users to test nodes.
core = 6.x
package = Example

This is test.module

  /**
* Implementation of hook_menu().
*/
  function test_menu() {
     $items['admin/test'] = array(
       'title' => 'Test disp',
       'description' => 'This is first example.',
       'page callback' => 'drupal_get_form',
       'page arguments' => array('test_disp'),
        'type' => MENU_NORMAL_ITEM,
   );
    return $items;
  }

  function test_disp(){
    $output.='<table><tr><td><p>This is first example.</p></td></tr></table>';
    return $output;
  }

First of all, Administrator didn't view my menu item (test disp) until I added a new row 'path'=>'admin/test'.
Second, whatever I clicked muen item(test disp) or visited http://localhost/admin/test, it always show the problem.

Page not found
Welcome to the administration section. Here you may control how your site functions.
The requested page could not be found.

I have no idea why it would like that. I'll really appreciate it if you explain the problem for me.

Comments

aburrows’s picture

flushed cache and run cron?

gz_hth’s picture

Yes, I did.

Drave Robber’s picture

Instead of

       'page callback' => 'drupal_get_form',
       'page arguments' => array('test_disp'),

you need

       'page callback' => 'test_disp',

because test_disp() returns an HTML output (string), not a form array.

gz_hth’s picture

Thanks for your reply. I tried with the way you gave, but the problem sitll happend. Perhaps there are other problems.

Drave Robber’s picture

As for adding items to admin menu: you can easily add items to existing categories, e.g., admin/settings/mytestitem or admin/build/mytestitem; to create a new category, you'd first need to do something like this:

  $items['admin/mycategory'] = array(
    'title' => 'My category',
    'description' => 'My new and cool admin page category',
    'page callback' => 'system_admin_menu_block_page',
    'type' => MENU_NORMAL_ITEM, 
    'access arguments' => array ('access administration pages'), // ...or whatever permission is appropriate.
    'file' => 'system.admin.inc',
    'file path' => drupal_get_path('module', 'system'),
  );

...and then you can go on with adding admin/mycategory/myitem etc.

abhishek sawant’s picture

function test_menu() {
  $items = array();
  $items['admin/test'] = array(
  'title' => 'Test disp',
  'description' => 'This is first example.',
  'page callback' => 'view_custom',
  'access arguments' => array('access content'),
  'type' => MENU_NORMAL_ITEM,
  );
 return $items;
}

function view_custom()
{
    $output = '';
    $output .= drupal_get_form('test_disp_form');
    return $output;
}

function test_disp_form(&$form_state)
{
 /** Insert your code..**/
}

Hope it helps.

Abhishek Sawant
Drupal Developer