문제

I'm new for Drupal , so I want to create a simple module that custom user profile, specically I want insert some tabs for user profile (the traditional user profile have 2 tabs "View tab" and "Edit Tab") so now I want add more 3 tabs.

  • Show History
  • Share profile
  • Shortcuts

but it only apply for user authenticated not admin profile (when admin show his profile ,the profile is traditional profile). So it my code (my module's name is :tung_tab) and here is code of tung_tab.module:

function tung_tab_menu() 
{
    $items = array();
    global $user;
        //if (!user_access('administer'))
        if($user->uid!=1)
     {
      $items['user/%/rvhistory'] = array(
        'title' => 'Review History ',
        'description' => 'Review History',
        //'page callback' => 'drupal_get_form',
        //'page arguments' => array('tung_tab_confirm_reviewh', 1),
        'access callback' => 'user_view_access',
        'access arguments' => array(1),
        'type' => MENU_LOCAL_TASK,
      );
      $items['user/%/sharehistory'] = array(
        'title' => 'Share History',
        'description' => 'Share History',
        //'page callback' => 'drupal_get_form',
        //'page arguments' => array('tung_tab_confirm_shareh', 1),
        'access callback' => 'user_view_access',
        'access arguments' => array(1),
        'type' => MENU_LOCAL_TASK,
      );
      $items['user/%/sc'] = array(
        'title' => 'Shortcut',
        'description' => 'Shortcut',
        //'page callback' => 'getDescription',
        //'page arguments' => array('tung_tab_confirm_shareh', 1),
        'access callback' => 'user_view_access',
        'access arguments' => array(1),
        'type' => MENU_LOCAL_TASK,
      );
     }
      return $items;
}

It work properlly for admin tab, but when I log out and then login with other user but not thing is changed, so if I comment the line //if($user->uid), everthing is ok so when I add more code in this line 'title' => 'Review History '.$user->uid, When I'm admin It show that Review History 1 When I loged in with another account , everything is the same , Review History 1 I can't understand why? I think my code get some mistake I put my module in "mysite/sites/default/modules/"

올바른 솔루션이 없습니다

다른 팁

You shouldn't define the menu items inside the if condition. You should control the access to the menu callbacks using access callback and access arguments instead.

WRONG:

function tung_tab_menu() 
{
    $items = array();
    global $user;
    if($user->uid!=1)
    {
        // defined menu items
    }
    return $items;
}

CORRECT:

function tung_tab_menu() 
{
    $items = array();
    global $user;
    // define the menu items here...
    return $items;
}

Try to fix that then see if you still get the same results.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top