I am writing a new module called mynode.module for learning the drupal system. The trouble is that I cant get the http://mysite.com/?q=mynode to get to generate what I want. I get a "Page Not Found".

My mynode_menu is as follows:

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

  if ($may_cache) {
    $items[] = array('path' => 'node/add/mynode', 'title' => t('New node type'),
      'access' => mynode_access('create', NULL));
    $items[] = array('path' => 'mynode', 'title' => t('New node type entries'),
      'callback' => 'mynode_page', 
      'access' => TRUE,                  /* Allow access for anybody */
        'type' => MENU_CALLBACK);
  }

  return $items;
}

I have coded mynode_page similar to blog_page_last() in the blog.module(basically, it generates last few posts of 'mynode' type). Still when I go to http://mysite.com/?q=mynode to get to generate what I want. I get a "Page Not Found" error.
What could be the reason that ?q=mynode is not recognized? Am I doing anything wrong in the hook_menu? How can I debug this?

Little bit background into what I did:
I started from page.module & changed it for mynode.module. In the process i created mynode_form, mynode_validate, mynode_insert, mynode_load, mynode_view as per documentation at 4.6 node_example.module
Now I am able to do node/add/mynode and view the posts & categories at ?q=taxonomy/term/num.

Thanks for any help

Comments

DriesK’s picture

Possibly, you tried a variation of your current code first, and then changed something when it didn't work. In that case, you should first clear your cache table, since the menu callback is in the $may_cache part of hook_menu.

aword’s picture

Thanks a lot Dries!! what you described was exactly the problem.
It works now..

Drupal is amazing!!

noid’s picture

How do you clear the cache table? I'm using phpmyadmin. Do I need it? Thanks. :)

benshell’s picture

DELETE FROM cache WHERE cid <> ''

Be sure to add your table prefix if you use one. Mine is drupal_cache.

It'd be nice to have a link in the adminstration section to do this. Of course it wouldn't be very hard to add it, I just haven't done so yet.

DriesK’s picture

In phpmyadmin, click the cache table, then click the "empty" tab (don't click "drop").

noid’s picture

Thanks guys! Is the query given by benshell the same as the emptying process posted by DriesK? Most probably will use the empty tab.

DriesK’s picture

if you click 'empty' in phpmyadmin, the query that is executed is "TRUNCATE TABLE 'cache'". The result is the same as deleting all rows, but how MySQL actually performs the operation may be different. However, this is not relevant when emptying Drupal's cache table :-)

pobster’s picture

I've been playing around writing a module which semi-integrates Squirrelmail into Drupal (don't get excited, it's honestly nothing special - literally just an onsite log on page which takes you straight into your Squirrelmail installation and an addressbook manager - global and users)... Anyways, so far it's been going okay... I'm getting on with it and everything worked fine, I've finished the redirect log on and the global addressbook manager but now all of a sudden in the settings page neither of the buttons at the bottom of the screen work...? (Save config, Reset) They 'used' to work because I tested them and I haven't altered the settings part of my code at all:

/**
 * Menu callback; Settings.
 */
function squirrelmail_settings() {
if (isset($_POST['test']))
{
 header("location: " . variable_get('squirrelmail_url') . "/src/configtest.php");
}
  $output1 = form_textfield(t('URL of Squirrelmail installation'), 'squirrelmail_url', variable_get('squirrelmail_url', 'http://localhost/mail'),
  60, 255, t('Include either "http://" or "https://" and leave NO trailing slash.'));
  $output1 .= form_textfield(t('Logo URL'), 'squirrelmail_logo', variable_get('squirrelmail_logo', 'images/sm_logo.png'), 60, 255, 'Relative to Squirrelmail installation.');
  $output1 .= form_textfield(t('Email Domain'), 'squirrelmail_domain', variable_get('squirrelmail_domain', 'localhost'), 60, 255, 'Your email domainname - ie. the part after youremail@...');
  $output1 .= form_checkbox(t('Profile module?'), 'squirrelmail_profile', variable_get('squirrelmail_profile', TRUE), TRUE, 'Do you have the profile module enabled in Squirrelmail?');
  $output2 = squirrelmail_display_addressbook('global_abook');
  $output2 .= '<p>' . l(t('Add new entry'), 'admin/settings/squirrelmail/add');
  $output1 .= form_submit(t('Test Settings'), 'test');
  $output = form_group(t('Squirrelmail Settings:'), $output1) . form_group(t('Global Addressbook:'), $output2);
return form($output);
}

I did however mess about with the permissions part, but as far as I can tell it looks okay now?

function squirrelmail_perm() {
  return array('access squirrelmail link', 'administer own addressbook', 'administer userprefs/ global addressbook');
}

function squirrelmail_menu($may_cache) {
  $items = array();
  // The $may_cache parameter is used to divide menu items into two parts. Those
  // returned when $may_cache is true must be consistently applicable for the
  // current user at all times; the others may change or be defined at only
  // certain paths. Most modules will have excusively cacheable menu items.
  if ($may_cache) {
    $items[] = array('path' => 'squirrelmail', 'title' => t('Squirrelmail'),
      'callback' => 'squirrelmail',
      'access' => user_access('access squirrelmail link'));
    $items[] = array('path' => 'squirrelmail/view', 'title' => t('View Addressbook'),
      'callback' => 'squirrelmail_view',
      'access' => user_access('administer own addressbook'),
      'type' => MENU_DYNAMIC_ITEM);
    $items[] = array('path' => 'squirrelmail/add', 'title' => t('Add Addressbook entry'),
      'callback' => 'squirrelmail_add',
      'access' => user_access('administer own addressbook'),
      'type' => MENU_CALLBACK);
    $items[] = array('path' => 'squirrelmail/edit', 'title' => t('Edit Addressbook entry'),
      'callback' => 'squirrelmail_edit',
      'access' => user_access('administer own addressbook'),
      'type' => MENU_CALLBACK);
    $items[] = array('path' => 'squirrelmail/delete', 'title' => t('Delete Addressbook entry'),
      'callback' => 'squirrelmail_delete',
      'access' => user_access('administer own addressbook'),
      'type' => MENU_CALLBACK);
    $items[] = array('path' => 'admin/settings/squirrelmail/add', 'title' => t('Add Global Addressbook entry'),
      'callback' => 'squirrelmail_add',
      'access' => user_access('administer userprefs/ global addressbook'),
      'type' => MENU_CALLBACK);
    $items[] = array('path' => 'admin/settings/squirrelmail/edit', 'title' => t('Edit Global Addressbook entry'),
      'callback' => 'squirrelmail_edit',
      'access' => user_access('administer userprefs/ global addressbook'),
      'type' => MENU_CALLBACK);
    $items[] = array('path' => 'admin/settings/squirrelmail/delete', 'title' => t('Delete Global Addressbook entry'),
      'callback' => 'squirrelmail_delete',
      'access' => user_access('administer userprefs/ global addressbook'),
      'type' => MENU_CALLBACK);
  }
  return $items;
}

Anyways, I emptied the cache hoping it'd be something simple like that, but nope... There's something wrong and I think I need a fresh pair of eyes to tell me what I'm overlooking. I'm sure I'm just being an idiot somewhere!

Thanks

Pobster

noid’s picture

Thanks, DriesK! Did use the empty tab -- this problem was the main hurdle to developing my Flexilist module -- http://drupal.org/node/34993 -- and it was smooth sailing after I figured out what was wrong. :)