2011-03-30 43 views
0

我已經使用PHP在我的模塊中以編程方式檢索視圖。如何檢索這個視圖的值?我使用的Drupal 6在PHP模塊開發中從視圖中檢索值

那是我的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> 

回答

0

我還沒有真正嘗試這個自己。首先要做的是執行視圖查詢。這可以通過execute函數完成。

所以做這樣的事情:

$view->execute('display_id'); 

應該填充$view對象至少有一些數據。可用數據因主題功能的不同層次而有所不同,因此您可能無法獲得您想要的內容。但這是我能想到的最好的方法。

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; 

$結果將包含每一行的值的陣列