【问题标题】:Drupal 7: how to get the modules listDrupal 7:如何获取模块列表
【发布时间】:2011-05-13 00:56:24
【问题描述】:

如何像 admin/build/modules 一样在 Drupal 中获取模块列表?

【问题讨论】:

  • 来自@Gokul:drush pm-list --type=Module --status=enabled

标签: php module drupal drupal-7 drupal-modules


【解决方案1】:

您可以使用drush pm-list --type=Module --status=enabled 命令获取已安装模块的列表。

更多选项,请查看http://www.drupaltonight.com/drupal-articles/using-drush-get-list-enabled-modules

【讨论】:

  • 谷歌搜索并最终使用了我在 2 年前提交的答案 :)
【解决方案2】:

安装“Drush”(无论如何都是一个不错的选择,一旦你习惯了它,你就会爱上它)。它有一个build in command 来列出所有已安装的模块主题。

如果您需要查看模块列表以在其他地方显示它(这可能是一个安全问题!),您可以查看 drush 是如何做到的 (pm.drush.inc:218)。

还有一个core function,不过不知道是不是你想要的。

【讨论】:

  • 我需要在 Web 界面中显示模块和主题列表,以便用户选择主题和模块
  • 那你为什么不能使用构建/模块视图呢?或者您是在说仅显示它而没有任何其他功能?
  • 我是新手构建/模块如何使用它? )
  • 这是你从上面给出的路径(我只是因为懒惰而省略了admin 部分;))
  • 你到底想做什么?登录管理员并启用/禁用模块和主题。无需编程。
【解决方案3】:
module_list($refresh = FALSE, $bootstrap_refresh = FALSE, $sort = FALSE, $fixed_list = NULL)

这里有更多细节。 http://api.drupal.org/api/drupal/includes!module.inc/function/module_list/7

【讨论】:

    【解决方案4】:

    如果您想列出所有可用的模块,这应该适用于 Drupal 6 或 Drupal 7:

    <?php
    // include_once('.' . base_path() . drupal_get_path('module', 'system') . '/system.admin.inc');
    // Above line was intentionally commented out (see below).
    $drupal_version = (int) VERSION;
    $list_modules_function = '';
    if ($drupal_version >= 7 && $drupal_version < 8) {
      $list_modules_function = 'system_rebuild_module_data';
    }
    else if ($drupal_version >= 6 && $drupal_version < 7) {
      $list_modules_function = 'module_rebuild_cache';
    }
    if (empty($list_modules_function)) {
      $output = t('Oops... Looks like you are not using either version 6 or version 7 of Drupal');
    }
    else if (!function_exists($list_modules_function)) {
      $output = t('Oops... Unable to find the function !function(). Try uncommenting the top line of this code.', array('!function' => $list_modules_function));
    }
    else {
      $output = "<dl>\n";
      $list_modules = $list_modules_function();
      foreach ($list_modules as $module) {
        $output .= "<dt>" . check_plain($module->info["name"]) . "</dt>\n";
        $output .= "<dd>" . check_plain($module->info["description"]) . "</dd>\n";
      }
      $output .= "</dl>\n";
    }
    print $output;
    ?>
    

    【讨论】:

    • 你能解释一下这里的 t() 是什么吗?我收到致命错误:调用未定义函数 t() 错误
    • t() 是一个用于多种目的的函数,但其​​主要目的是翻译文本。请参阅此API documentation 了解更多信息。
    【解决方案5】:

    您还可以使用以下命令搜索特定模块。 如果你想从模块列表中只列出商业模块而不是

    drush pml | grep commerce
    

    在 windows 机器上你不能使用 grep。所以你必须使用 findstr

    drush pml | findstr commerce
    

    【讨论】:

      【解决方案6】:

      以下命令将起作用,输出所有可用模块的列表以及它们所在的包、状态和版本。

      drush pm-list --type=Module --status=enabled
      

      【讨论】:

      • 不太好从其中一个 cmets 复制答案 ;)
      • 刚刚使用它,它对我有用。我没有足够的声誉来为任何评论或问题 +1,所以我认为写出对我有用的东西将支持解决方案......:p:D
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多