In my custom Drupal 7 module I am using CUSTOM_MODULE_NAME_init() function. But it is not triggered while page execution. Any suggestions?

link|improve this question
1  
you'll get better answers if we can see your code. try gist.github.com or drupalbin.com – barraponto Aug 23 '11 at 11:39
feedback

3 Answers

  1. Make sure that the module is enabled (don't laugh, I forget that sometimes).
  2. Make sure that the page is not served from cache. Use hook_boot if you need to perform setup tasks for cached pages.
  3. Use a debugger to step through the execution. hook_init is invoked at the end of _drupal_bootstrap_full.
link|improve this answer
How to debug the execution? – Vinoth Aug 23 '11 at 10:28
Caveman debugging: put print_r statements at relevant places of the code to get feedback about which parts of the code are executed and what values the variables hold. Because this is tedious if done often, a better solution is to install a debugging extension on the server, e.g. Xdebug and using an IDE that can controll the debugger, e.g. Eclipse PDT. – Oswald Aug 23 '11 at 10:40
feedback

Hook implementations are cached in Drupal 7. After implementing a new hook, you need to clear the cache. See What method is used to clear caches in the Drupal? for ways to do that.

link|improve this answer
Yes. I cleared the cache. But not invoked – Vinoth Aug 23 '11 at 10:28
feedback

As reported in the documentation for hook_init(), the hook is not invoked on cached pages. This means that, if the content of a page is found in cache, the hook implemented by your module is not invoked.

This hook is run at the beginning of the page request. It is typically used to set up global parameters which are needed later in the request. when this hook is called, all modules are already loaded in memory.

This hook is not run on cached pages.

To add CSS or JS that should be present on all pages, modules should not implement this hook, but declare these files in their .info file.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.