1

I am trying to create a new module implementing hook_menu, to render a page on my company's web site, which I have taken over from the external firm who designed it. There are other modules that use the hook_menu mechanism successfully on the site.

However, when I create my module and try to access my new page, I get a message indicating "Error. The website encountered an unexpected error. Please try again later.", with no real indication of what the error is.

Here is my code:

<?php

function customer_stories_menu(){
    $items['test'] = array(
        'title' => 'Products Display',
        'title callback' => 'customer_stories_title',
        'page callback' => 'customer_stories_page',
        'access arguments' => array('access content'),
        'type' => MENU_CALLBACK,
    );

    return $items;
}

function customer_stories_page() {  
    return "Test 123";
}

function customer_stories_title() {
    return "Title";
}

I have made sure that I cleared the cache after putting the code in place. Could something in the site be preventing new hook_menu pages from working?

I should also mention that I first tried creating a new view page to get to the data I wanted to display, but I also got a non-descript error page when I tried to access the defined URL for the page. The two issues may be related. Thanks for any help you can provide.

0

I've got this noted down as my starting point for a module .

function helloworld_menu() {

$menu['helloworld/hello'] = array(
    'title' => 'Hello World',
    'page callback' => 'helloworld_hello',
'access callback' => TRUE,
);
   return $menu;
  }

function helloworld_hello() {
   return 'Hello World';
 };

do you still get an error if you take it back to this point.

  • Yes, I still get an error with this basic code. Doing some tests on a brand new install in parallel, the code works perfectly fine on a clean install, pointing to something preventing this from working on the site where I am trying to implement this. – ylefebvre Jun 20 '14 at 14:37
  • I took the extreme route of deactivating all modules on my site and bringing them back in one by one. The culprit is a module called PHP Filter. When enabled, my custom hook_menu page does not work. When disabled, it displays as expected. Going to see if there is a configuration page for this plugin that needs to be edited. Any familiarity with this module causing this type of issue? – ylefebvre Jun 20 '14 at 18:15
0

I had code in one of my blocks that was causing an error. It was missing a condition to exit when getting called on a new page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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