从PHP模块开发中的视图中检索值

时间:2011-03-30 09:23:32

标签: php drupal drupal-6 drupal-views drupal-modules

我已经使用PHP在我的模块中以编程方式检索视图。如何检索此视图的值?我正在使用drupal 6。

这是我的PHP代码中的视图结果:

   enter code hereobject(view)#48 (22) {
  ["db_table"]=>
  string(10) "views_view"
  ["base_table"]=>
  string(4) "node"
  ["args"]=>
  array(0) {
  }
  ["use_ajax"]=>
  bool(false)
  ["result"]=>
  array(0) {
  }
  ["pager"]=>
  array(5) {
    ["use_pager"]=>
    bool(false)
    ["items_per_page"]=>
    int(10)
    ["element"]=>
    int(0)
    ["offset"]=>
    int(0)
    ["current_page"]=>
    int(0)
  }
  ["old_view"]=>
  array(0) {
  }
  ["vid"]=>
  string(2) "48"
  ["name"]=>
  string(7) "student"
  ["description"]=>
  string(7) "Student"
  ["tag"]=>
  string(0) ""
  ["view_php"]=>
  string(0) ""
  ["is_cacheable"]=>
  string(1) "0"
  ["display"]=>
  array(2) {
    ["default"]=>
    object(views_display)#11 (7) {
      ["db_table"]=>
      string(13) "views_display"
      ["vid"]=>
      string(2) "48"
      ["id"]=>
      string(7) "default"
      ["display_title"]=>
      string(8) "Defaults"
      ["display_plugin"]=>
      string(7) "default"
      ["position"]=>
      string(1) "1"
      ["display_options"]=>
      array(2) {
        ["fields"]=>
        array(5) {
          ["field_locatie_student_lid"]=>
          array(14) {
            ["label"]=>
            string(7) "Locatie"
            ["alter"]=>
            array(16) {
              ["alter_text"]=>
              int(0)
              ["text"]=>
              string(0) ""
              ["make_link"]=>
              int(0)
              ["path"]=>
              string(0) ""
              ["link_class"]=>
              string(0) ""
              ["alt"]=>
              string(0) ""
              ["prefix"]=>
              string(0) ""
              ["suffix"]=>
              string(0) ""
              ["target"]=>
              string(0) ""
              ["help"]=>
              string(0) ""
              ["trim"]=>
              int(0)
              ["max_length"]=>
              string(0) ""
              ["word_boundary"]=>
              int(1)
              ["ellipsis"]=>
              int(1)
              ["html"]=>
              int(0)
              ["strip_tags"]=>
              int(0)
            }
            ["empty"]=>
            string(41) "geen overeenkomstige resultaten gevonden."
            ["hide_empty"]=>
            int(0)
            ["empty_zero"]=>
            int(0)
            ["link_to_node"]=>
            int(0)
            ["label_type"]=>
            string(6) "widget"
            ["format"]=>
            string(7) "default"
            ["multiple"]=>
            array(4) {
              ["group"]=>
              bool(true)
              ["multiple_number"]=>
              string(0) ""
              ["multiple_from"]=>
              string(0) ""
              ["multiple_reversed"]=>
              bool(false)
            }
            ["exclude"]=>
            int(0)
            ["id"]=>
            string(25) "field_locatie_student_lid"
            ["table"]=>
            string(31) "node_data_field_locatie_student"
            ["field"]=>
            string(25) "field_locatie_student_lid"
            ["relationship"]=>
            string(4) "none"
          }
          ["field_naam_student_value"]=>
          array(14) {
            ["label"]=>
            string(4) "Naam"
            ["alter"]=>
            array(16) {
              ["alter_text"]=>
              int(0)
              ["text"]=>
              string(0) ""
              ["make_link"]=>
              int(0)
              ["path"]=>
              string(0) ""
              ["link_class"]=>
              string(0) ""
              ["alt"]=>
              string(0) ""
              ["prefix"]=>
              string(0) ""
              ["suffix"]=>
              string(0) ""
              ["target"]=>
              string(0) ""
              ["help"]=>
              string(0) ""
              ["trim"]=>
              int(0)
              ["max_length"]=>
              string(0) ""
              ["word_boundary"]=>
              int(1)
              ["ellipsis"]=>
              int(1)
              ["html"]=>
              int(0)
              ["strip_tags"]=>
              int(0)
            }
            ["empty"]=>
            string(41) "geen overeenkomstige resultaten gevonden."
            ["hide_empty"]=>
            int(0)
            ["empty_zero"]=>
            int(0)
            ["link_to_node"]=>
            int(0)
            ["label_type"]=>
            string(6) "widget"
            ["format"]=>
            string(7) "default"
            ["multiple"]=>
            array(4) {
              ["group"]=>
              bool(true)
              ["multiple_number"]=>
              string(0) ""
              ["multiple_from"]=>
              string(0) ""
              ["multiple_reversed"]=>
              bool(false)
            }
            ["exclude"]=>
            int(0)
            ["id"]=>
            string(24) "field_naam_student_value"
            ["table"]=>
            string(28) "node_data_field_naam_student"
            ["field"]=>
            string(24) "field_naam_student_value"
            ["relationship"]=>
            string(4) "none"
          }
          ["field_ugentid_student_value"]=>
          array(14) {
            ["label"]=>
            string(7) "UGentID"
            ["alter"]=>
            array(16) {
              ["alter_text"]=>
              int(0)
              ["text"]=>
              string(0) ""
              ["make_link"]=>
              int(0)
              ["path"]=>
              string(0) ""
              ["link_class"]=>
              string(0) ""
              ["alt"]=>
              string(0) ""
              ["prefix"]=>
              string(0) ""
              ["suffix"]=>
              string(0) ""
              ["target"]=>
              string(0) ""
              ["help"]=>
              string(0) ""
              ["trim"]=>
              int(0)
              ["max_length"]=>
              string(0) ""
              ["word_boundary"]=>
              int(1)
              ["ellipsis"]=>
              int(1)
              ["html"]=>
              int(0)
              ["strip_tags"]=>
              int(0)
            }
            ["empty"]=>
            string(41) "geen overeenkomstige resultaten gevonden."
            ["hide_empty"]=>
            int(0)
            ["empty_zero"]=>
            int(0)
            ["link_to_node"]=>
            int(0)
            ["label_type"]=>
            string(6) "widget"
            ["format"]=>
            string(7) "default"
            ["multiple"]=>
            array(4) {
              ["group"]=>
              bool(true)
              ["multiple_number"]=>
              string(0) ""
              ["multiple_from"]=>
              string(0) ""
              ["multiple_reversed"]=>
              bool(false)
            }
            ["exclude"]=>
            int(0)
            ["id"]=>
            string(27) "field_ugentid_student_value"
            ["table"]=>
            string(31) "node_data_field_ugentid_student"
            ["field"]=>
            string(27) "field_ugentid_student_value"
            ["relationship"]=>
            string(4) "none"
          }
          ["field_voornaam_student_value"]=>
          array(14) {
            ["label"]=>
            string(8) "Voornaam"
            ["alter"]=>
            array(16) {
              ["alter_text"]=>
              int(0)
              ["text"]=>
              string(0) ""
              ["make_link"]=>
              int(0)
              ["path"]=>
              string(0) ""
              ["link_class"]=>
              string(0) ""
              ["alt"]=>
              string(0) ""
              ["prefix"]=>
              string(0) ""
              ["suffix"]=>
              string(0) ""
              ["target"]=>
              string(0) ""
              ["help"]=>
              string(0) ""
              ["trim"]=>
              int(0)
              ["max_length"]=>
              string(0) ""
              ["word_boundary"]=>
              int(1)
              ["ellipsis"]=>
              int(1)
              ["html"]=>
              int(0)
              ["strip_tags"]=>
              int(0)
            }
            ["empty"]=>
            string(41) "geen overeenkomstige resultaten gevonden."
            ["hide_empty"]=>
            int(0)
            ["empty_zero"]=>
            int(0)
            ["link_to_node"]=>
            int(0)
            ["label_type"]=>
            string(6) "widget"
            ["format"]=>
            string(7) "default"
            ["multiple"]=>
            array(4) {
              ["group"]=>
              bool(true)
              ["multiple_number"]=>
              string(0) ""
              ["multiple_from"]=>
              string(0) ""
              ["multiple_reversed"]=>
              bool(false)
            }
            ["exclude"]=>
            int(0)
            ["id"]=>
            string(28) "field_voornaam_student_value"
            ["table"]=>
            string(32) "node_data_field_voornaam_student"
            ["field"]=>
            string(28) "field_voornaam_student_value"
            ["relationship"]=>
            string(4) "none"
          }
          ["field_voorkeur_student_value"]=>
          array(14) {
            ["label"]=>
            string(19) "Voorkeurstageplaats"
            ["alter"]=>
            array(16) {
              ["alter_text"]=>
              int(0)
              ["text"]=>
              string(0) ""
              ["make_link"]=>
              int(0)
              ["path"]=>
              string(0) ""
              ["link_class"]=>
              string(0) ""
              ["alt"]=>
              string(0) ""
              ["prefix"]=>
              string(0) ""
              ["suffix"]=>
              string(0) ""
              ["target"]=>
              string(0) ""
              ["help"]=>
              string(0) ""
              ["trim"]=>
              int(0)
              ["max_length"]=>
              string(0) ""
              ["word_boundary"]=>
              int(1)
              ["ellipsis"]=>
              int(1)
              ["html"]=>
              int(0)
              ["strip_tags"]=>
              int(0)
            }
            ["empty"]=>
            string(41) "geen overeenkomstige resultaten gevonden."
            ["hide_empty"]=>
            int(0)
            ["empty_zero"]=>
            int(0)
            ["link_to_node"]=>
            int(0)
            ["label_type"]=>
            string(6) "widget"
            ["format"]=>
            string(7) "default"
            ["multiple"]=>
            array(4) {
              ["group"]=>
              bool(true)
              ["multiple_number"]=>
              string(0) ""
              ["multiple_from"]=>
              string(0) ""
              ["multiple_reversed"]=>
              bool(false)
            }
            ["exclude"]=>
            int(0)
            ["id"]=>
            string(28) "field_voorkeur_student_value"
            ["table"]=>
            string(32) "node_data_field_voorkeur_student"
            ["field"]=>
            string(28) "field_voorkeur_student_value"
            ["relationship"]=>
            string(4) "none"
          }
        }
        ["filters"]=>
        array(2) {
          ["type"]=>
          array(9) {
            ["operator"]=>
            string(2) "in"
            ["value"]=>
            array(1) {
              ["student"]=>
              string(7) "student"
            }
            ["group"]=>
            string(1) "0"
            ["exposed"]=>
            bool(false)
            ["expose"]=>
            array(2) {
              ["operator"]=>
              bool(false)
              ["label"]=>
              string(0) ""
            }
            ["id"]=>
            string(4) "type"
            ["table"]=>
            string(4) "node"
            ["field"]=>
            string(4) "type"
            ["relationship"]=>
            string(4) "none"
          }
          ["field_ugentid_student_value"]=>
          array(9) {
            ["operator"]=>
            string(9) "not empty"
            ["value"]=>
            array(3) {
              ["value"]=>
              string(0) ""
              ["min"]=>
              string(0) ""
              ["max"]=>
              string(0) ""
            }
            ["group"]=>
            string(1) "0"
            ["exposed"]=>
            bool(false)
            ["expose"]=>
            array(2) {
              ["operator"]=>
              bool(false)
              ["label"]=>
              string(0) ""
            }
            ["id"]=>
            string(27) "field_ugentid_student_value"
            ["table"]=>
            string(31) "node_data_field_ugentid_student"
            ["field"]=>
            string(27) "field_ugentid_student_value"
            ["relationship"]=>
            string(4) "none"
          }
        }
      }
    }
    ["page_1"]=>
    object(views_display)#43 (7) {
      ["db_table"]=>
      string(13) "views_display"
      ["vid"]=>
      string(2) "48"
      ["id"]=>
      string(6) "page_1"
      ["display_title"]=>
      string(6) "Pagina"
      ["display_plugin"]=>
      string(4) "page"
      ["position"]=>
      string(1) "2"
      ["display_options"]=>
      array(1) {
        ["path"]=>
        string(17) "studentenLijstCSV"
      }
    }
  }
  ["type"]=>
  string(6) "Normal"
  ["loaded"]=>
  bool(true)
  ["executed"]=>
  bool(false)
  ["built"]=>
  bool(false)
  ["build_info"]=>
  array(0) {
  }
  ["attachment_before"]=>
  string(0) ""
  ["attachment_after"]=>
  string(0) ""
  ["get_total_rows"]=>
  bool(true)
}
<div style="display: none" id="drupalforfirebug_general"><fieldset><legend>Drupal for Firebug General Messages</legend>There were no messages sent to the general log. Please use "firep($item, $optional_title)" to output messages to this console.</div><div style="display: none" id="drupalforfirebug_sql"><fieldset><legend>Devel Module is Not Installed</legend>Please install and enable the Devel Module to display the SQL queries.</fieldset></div><div style="display: none" id="drupalforfirebug_hook_form_alter">There was no form altering.</div><div style="display: none" id="drupalforfirebug_hook_user">There was no user processing.</div><div style="display: none" id="drupalforfirebug_hook_nodeapi">There was no node processing.</div><div style="display: none" id="drupalforfirebug_hook_views">There was no views processing.</div><div style="display: none" id="drupalforfirebug_php"><object style="width:100%;frameborder=0;height=100%;margin-bottom:-3px;" type="text/html" data="http://localhost/testplanning/?q=admin/firebug/exec"></object></div><div style="display: none" id="drupalforfirebug_hook_page_alter">This feature is only available in Drupal 7.</div>

2 个答案:

答案 0 :(得分:1)

为什么你不仅仅使用观点?

$view = view_get_view('MY_VIEW_NAME');
$view->set_display('MY_DISPLAY'); // page_1 or block_1 ... block_n, ...page_n
$view->set_items_per_page(0);
$view->execute();
$result = $view->result;

$ result将包含每行的值数组

答案 1 :(得分:0)

我自己并没有真正试过这个。首先要做的是执行视图查询。这可以使用execute函数完成。

所以做这样的事情:

$view->execute('display_id');

应该使用至少一些数据填充$view对象。可用的数据因主题功能的不同层次而异,因此您可能无法获得所需的数据。但这是我能想到的最佳方法。