0

I'm loading a datatable and its data into a panel, through ajax. Below is the link which can add the row(entry) to favorites. When I click the link, the jquery animation is executed properly but the hook_menu and it's callback function is not being executed. It looks like the hook_menu is not 'available'

This is the link

$link = array(
    '#type' => 'link',
    '#title' => t('Favorite'),
    '#href' => 'favorite/' . $item->nid,
    '#attributes' => array(
    'class' => array('use-ajax', 'favorite_item_button'),
    ), 
);

And this is the hook_menu

function favorite_item_menu() {
  $items = array();
  $items['favorite/%'] = array(
    'title' => 'favorite item',
    'page callback' => 'favorite_item',
    'page arguments' => array(1),
    'type' => MENU_CALLBACK,
  );

  return $items;
}

Do you see any mistakes? Am I doing something wrong, forgetting something?

Advice is much appreciated.

Edit: - no php error logs - no js error logs

tried: sitename.com/favorite/501 - got the error 'access denied'

13
  • did you clear Drupal cache?
    – Aboodred1
    May 8, 2013 at 20:15
  • yes I did, caching is not the problem. Also the JS is attached properly because the jquery animation works. More suggestions ? : ) May 8, 2013 at 20:17
  • when you add the link in the address bar what do you get e.g. http://domain.com/favorite/54
    – Aboodred1
    May 8, 2013 at 20:23
  • hmm, access denied is what I get. Does this mean I should add access arguments? May 8, 2013 at 20:28
  • 1
    let us continue this discussion in chat
    – Aboodred1
    May 8, 2013 at 21:08

1 Answer 1

1

You need to add 'access callback' => TRUE, to your menu item.

Your menu callback should look like the following:

function favorite_item_menu() {
  $items = array();

  $items['favorite/%'] = array(
    'title' => 'favorite item',
    'page callback' => 'favorite_item',
    'page arguments' => array(1),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );

  return $items;
}

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.