views_get_view_result

function views_get_view_result

views_get_view_result($name, $display_id = NULL)

Get the result of a view.

Parameters

string $name: The name of the view to retrieve the data from.

string $display_id: The display id. On the edit page for the view in question, you'll find a list of displays at the left side of the control area. "Master" will be at the top of that list. Hover your cursor over the name of the display you want to use. A URL will appear in the status bar of your browser. This is usually at the bottom of the window, in the chrome. Everything after #views-tab- is the display ID, e.g. page_1.

...: Any additional parameters will be passed as arguments.

Return value

array An array containing an object for each view item.

File

core/modules/views/views.module, line 770
Primarily Drupal hooks and global API functions to manipulate views.

Code

function views_get_view_result($name, $display_id = NULL) {
  $args = func_get_args();
  // Remove $name and $display_id from the arguments.
  unset($args[0], $args[1]);

  $view = Views::getView($name);
  if (is_object($view)) {
    if (is_array($args)) {
      $view->setArguments($args);
    }
    if (is_string($display_id)) {
      $view->setDisplay($display_id);
    }
    else {
      $view->initDisplay();
    }
    $view->preExecute();
    $view->execute();
    return $view->result;
  }
  else {
    return array();
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!views!views.module/function/views_get_view_result/8.1.x

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部