0

I have create simple hook_menu but when i clear cache retrieve Page not Found

function sanabel_calculator_menu() {
  $items = array();
  $items['iban_generator'] = array(
    'title' =>  t('IBAN'),
    'page callback' => 'iban_generator',
    'access callback' => true,
  );

  return $items;
}
function iban_generator(){
  $branch = $_GET['branch'];
  $accountNumber = $_GET['accountNumber'];
  $number_format = "11192427" . $branch . "00" . $accountNumber . "192400";
  $checkdigit = 98 - ( $number_format % 97 );
  $iban = 'JO' . $checkdigit . 'BJOR' . $branch . '00' . $accountNumber;
  $output = '<table border="1" > <tbody> <tr> <td>' . t("Account Number") . '</td>
    <td>' . t('IBAN') . '</td></tr>
    <tr>  <td>' . $accountNumber . '</td><td>' . $iban . '</td></tr>
    </tbody></table> <p>'. l(t('Back'), $back_form) .'</p>';
  return drupal_set_message($output);
}

How can fix this problem ??

4
  • Hello and welcome. You stated a fact. Please make it into a question. and remember - we are not a free debugging service.
    – Mołot
    Sep 30, 2014 at 8:01
  • Is it working if you replace all the code inside you iban_generator function by "return drupal_set_message('hello');" ?
    – Djouuuuh
    Sep 30, 2014 at 8:02
  • No not work and give me page not found Sep 30, 2014 at 8:03
  • 1
    It may be obvious... but... did you flush your menu cache?
    – 2pha
    Sep 30, 2014 at 8:40

2 Answers 2

1

Follow this checklist and it will work:

  • Make sure your module is called sanabel_calculator. If it isn't, change sanabel_calculator_menu() to MODULE_NAME_menu(). It's wise to use your module name to prefix all functions that it defines, as a rudimentary namespacing system. You might want to change iban_generator() to sanabel_calculator_generator() as part of that, to avoid confustion in the future.
  • Return something meaningful from your function. drupal_set_message() can return NULL, and other than that will only ever return a plain array. This is not acceptable as a page callback result, which needs to be a render array (or, less ideally, a string).
  • Make sure the module is enabled
  • Clear Drupal's caches

As an aside, consider defining a proper access callback or at least arguments for your page. It may not matter, but it's a good practice to get into.

If it still doesn't work after that, follow the steps again through again. If it still doesn't work, you've got something wrong with your installation. Try to install the module on a fresh copy of Drupal to confirm that.

1

you should return $output;

function iban_generator(){
  $branch = $_GET['branch'];
  $accountNumber = $_GET['accountNumber'];
  $number_format = "11192427" . $branch . "00" . $accountNumber . "192400";
  $checkdigit = 98 - ( $number_format % 97 );
  $iban = 'JO' . $checkdigit . 'BJOR' . $branch . '00' . $accountNumber;
  $output = '<table border="1" > <tbody> <tr> <td>' . t("Account Number") . '</td>
    <td>' . t('IBAN') . '</td></tr>
    <tr>  <td>' . $accountNumber . '</td><td>' . $iban . '</td></tr>
    </tbody></table> <p>'. l(t('Back'), $back_form) .'</p>';
  return $output;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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