Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 421 Vote(s) - 3.55 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to throw 404 error in Drupal module?

#1
I need to throw 404 error in module. Or may be there are any possibility to set required option for menu hook?
Reply

#2
`MENU_NOT_FOUND` should be returned in page callback functions.

> Page callback functions wanting to report a "page not found" message should return MENU_NOT_FOUND instead of calling drupal_not_found().

[To see links please register here]

Reply

#3
Look into the drupal_add_http_header() function to play with the HTTP header attributes. Also make sure you stick this at the top of your module's code to make sure it executes first. Also, you might find this helpful.

[To see links please register here]

Reply

#4
It is easy. These should take care of watchdog, HTTP 404 response code and other related things.

**For Drupal 6 & 7**

In your module's page callback, do: `return drupal_not_found();`

**For Drupal 8**

In the `class::method()` referred to in the `_controller` definition (i.e. the page callback or the method responsible for generating output for the request), do:

`throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();`

**References**

* [drupal_not_found() documentation for Drupal 6][1].
* [drupal_not_found() documentation for Drupal 7][2].
* [NotFoundHttpException documentation for Drupal 8][3].

[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

Reply

#5
For Drupal 8+

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
// then
throw new NotFoundHttpException();
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through