doulongsi1831 2011-10-14 13:34
浏览 12

如何在drupal中以编程方式访问模块?

based on some condition i want to give access to a module.

if(abc == abc) {
  //give access to module xyz.
}
  • 写回答

1条回答 默认 最新

  • dqq3623 2011-10-14 14:55
    关注

    There's no such concept as giving access to a whole module in Drupal, only pages that a module would define. Usually this is done by implementing hook_menu() to define the page(s) and then providing either an access callback or access arguments.

    The first defines a function that will be called to make your access decision:

    function mymodule_menu() {
      $items['some/path'] = array(
        'title' => 'Some Title',
        'page callback' => 'mymodule_callback',
        'access callback' => 'mymodule_some_path_access'
      );
    
      return $items;
    }
    
    function mymodule_some_path_access() {
      global $user;
    
      if ($user->foo == 'bar') {
        // Access allowed, return TRUE
        return TRUE;
      }
    
      // Access not allowed, return FALSE
      return FALSE;
    }
    

    The second defines arguments that will be passed to the user_access function. This will usually be based on permissions your module provides:

    function mymodule_menu() {
      $items['some/path'] = array(
        'title' => 'Some Title',
        'page callback' => 'mymodule_callback',
        'access arguments' => array('access mymodule')
      );
    
      return $items;
    }
    
    function mymodule_perm() {
      return array(
        'access mymodule'
      );
    }
    

    In the second example a user will be denied access unless they have the permission 'access mymodule' (as defined in the permissions admin area of Drupal).

    Hope that helps

    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据