【发布时间】: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
如何像 admin/build/modules 一样在 Drupal 中获取模块列表?
【问题讨论】:
drush pm-list --type=Module --status=enabled
标签: php module drupal drupal-7 drupal-modules
您可以使用drush pm-list --type=Module --status=enabled 命令获取已安装模块的列表。
更多选项,请查看http://www.drupaltonight.com/drupal-articles/using-drush-get-list-enabled-modules
【讨论】:
安装“Drush”(无论如何都是一个不错的选择,一旦你习惯了它,你就会爱上它)。它有一个build in command 来列出所有已安装的模块主题。
如果您需要查看模块列表以在其他地方显示它(这可能是一个安全问题!),您可以查看 drush 是如何做到的 (pm.drush.inc:218)。
还有一个core function,不过不知道是不是你想要的。
【讨论】:
admin 部分;))
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
【讨论】:
如果您想列出所有可用的模块,这应该适用于 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;
?>
【讨论】:
您还可以使用以下命令搜索特定模块。 如果你想从模块列表中只列出商业模块而不是
drush pml | grep commerce
在 windows 机器上你不能使用 grep。所以你必须使用 findstr
drush pml | findstr commerce
【讨论】:
以下命令将起作用,输出所有可用模块的列表以及它们所在的包、状态和版本。
drush pm-list --type=Module --status=enabled
【讨论】: