Posted by ifuyivara on November 26, 2012 at 5:33pm
Hello,
I have a custom Drupal module with the hook_menu implementation where I declare a callback like this:
<?php
function news_menu() {
$items = array();
$items['news'] = array(
'title' => 'News',
'page callback' => 'news_page',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
?>If I visit the page www.mydomain.com/news I get the response from the news_page function which is good but if I go to the page news/foo I still get the response from the news_page function instead of a 404 which is what I would expect. I know the default behavior of Drupal is passing foo as an argument to the function and that's why I'm not getting the page not found.
I'm wondering how can I prevent this behavior?
Thanks
Comments
You can create an item for
You can create an item for the path 'news/%' with drupal_not_found as its callback. But that'll only solve the problem for this specific path. There's not as far as I know a way to override this behaviour in Drupal globally, assuming that's what you are asking: it would probably break some modules.
The thing you can do here is
The thing you can do here is write a access callback function for the 'news' path you've mentioned. Write the following code in that function.
if (!empty(arg(1)) {return FALSE;
}
else {
return TRUE;
}
So, when a user types a URL 'news/foo' or 'news/foo/bar' or with further arguments. He'll get the access denied page.
Thanks!
Aditya
Drupal Developer