drupal - 如何在 Drupal 7 中使用代码创建 View ?

标签 drupal drupal-7 drupal-modules drupal-views

我们可以从管理面板创建一个 View 。但我想使用 php 代码创建一个 View 。谁能给我指路?

最佳答案

有一些代码对我不起作用。但是这个做到了。将此 php 添加到您的 .module 文件中。然后创建一个 views 文件夹,然后将所有 View 放在其中,扩展名为 .inc。每个 View 文件都是 <?php然后是 View 的精确导出...

/**
* Implements hook_views_api().
*/
function MODULENAME_views_api() {
  return array ('api' => 3.0);
}

function MODULENAME_views_default_views() {
  // Check for all view file in views directory
  $files = file_scan_directory(drupal_get_path('module', 'MODULENAME') . '/views', '/.*\.inc$/');

  // Add view to list of views
  foreach ($files as $filepath => $file) {
    require $filepath;
    if (isset($view)) {
      $views[$view->name] = $view;
    }
  }

  // At the end, return array of default views.
  return $views;
}

关于drupal - 如何在 Drupal 7 中使用代码创建 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14907754/

相关文章:

datetime - Drupal 7 规则 - 在 cron 上,检查日期字段,如果过去设置字段 [状态] 从 “active” 到 “ended”

https - 为什么谷歌分析 JavaScript 文件无法加载?

drupal - 如何通过 theme-setting.php 以 drupal 形式正确添加 FILE 字段?

Drupal 保存数据 hook_form_alter

html - CSS 未正确更新

javascript - 在 Drupal 7 中缩小 CSS 和 JS 文件的最佳方法是什么?

drupal - Drupal 可以与 PostGIS 一起使用以进行空间查询吗?

drupal - 如何将 Drupal 书籍导出为 PDF?

php - 多次调用通配符加载器函数 (_load)

php - Drupal 大量查询