2010-01-30 12 views
5

Tôi đang cố mô-đun filefield_stats để cung cấp dữ liệu đó cho khả năng hiển thị dữ liệu vào mô-đun Views qua API. Giản đồ filefield_stats là như sau:Hiển thị dữ liệu của mô-đun cho Chế độ xem2 sử dụng API

function filefield_stats_schema() { 
    $schema['filefield_stats'] = array(
    'fields' => array(  
     'fid'  => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'Primary Key: the {files}.fid'), 
     'vid'  => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'Primary Key: the {node}.vid'),  
     'uid'  => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'The {users}.uid of the downloader'), 
     'timestamp' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'The timestamp of the download'), 
     'hostname' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => '', 'description' => 'The hostname downloading the file (usually IP)'), 
     'referer' => array('type' => 'text', 'not null' => FALSE, 'description' => 'Referer for the download'), 
    ), 
    'indexes' => array('fid_vid' => array('fid', 'vid')), 
); 
    return $schema; 
} 

Vâng, vì vậy tôi thực hiện các hook_views_api() trong filefield_stats.module & thêm một filefield_stats.views.inc tập tin trong thư mục gốc của mô-đun, đây nó là:

// $Id$ 

/** 
* @file 
* Provide the ability of exposing data to Views2, for filefield_stats module. 
*/ 

function filefield_stats_views_data() { 
    $data = array(); 
    $data['filefield_stats']['table']['group'] = t('FilefieldStats'); 

    // Referencing the {node_revisions} table. 
    $data['filefield_stats']['table']['join'] = array(
     'node_revisions' => array(
      'left_field' => 'vid', 
      'field' => 'vid', 
     ), 
     'files' => array(
      'left_field' => 'fid', 
      'field' => 'fid', 
     ), 
     'users' => array(
      'left_field' => 'uid', 
      'field' => 'uid', 
     ), 
    ); 

    // Introducing filefield_stats table fields to Views2. 
    // vid: The node's revision ID which wrapped the downloaded file 
    $data['filefield_stats']['vid'] = array(
     'title' => t('Node revision ID'), 
     'help' => t('The node\'s revision ID which wrapped the downloaded file'), 
     'relationship' => array(
      'base' => 'node_revisions', 
      'field' => 'vid', 
      'handler' => 'views_handler_relationship', 
      'label' => t('Node Revision Reference.'), 
     ), 
    ); 

    // uid: The ID of the user who downloaded the file. 
    $data['filefield_stats']['uid'] = array(
     'title' => t('User ID'), 
     'help' => t('The ID of the user who downloaded the file.'), 
     'relationship' => array(
      'base' => 'users', 
      'field' => 'uid', 
      'handler' => 'views_handler_relationship', 
      'label' => t('User Reference.'), 
     ), 
    ); 

    // fid: The ID of the downloaded file. 
    $data['filefield_stats']['fid'] = array(
     'title' => t('File ID'), 
     'help' => t('The ID of the downloaded file.'), 
     'relationship' => array(
      'base' => 'files', 
      'field' => 'fid', 
      'handler' => 'views_handler_relationship', 
      'label' => t('File Reference.'), 
     ), 
    ); 

    // hostname: The hostname which the file has been downloaded from. 
    $data['filefield_stats']['hostname'] = array(
     'title' => t('The Hostname'), 
     'help' => t('The hostname which the file has been downloaded from.'), 
     'field' => array(
      'handler' => 'views_handler_field', 
      'click sortable' => TRUE, 
     ), 
     'sort' => array(
      'handler' => 'views_handler_sort', 
     ), 
     'filter' => array(
      'handler' => 'views_handler_filter_string', 
     ), 
     'argument' => array(
      'handler' => 'views_handler_argument_string', 
     ), 
    ); 

    // referer: The referer address which the file download link has been triggered from. 
    $data['filefield_stats']['referer'] = array(
     'title' => t('The Referer'), 
     'help' => t('The referer which the file download link has been triggered from.'), 
     'field' => array(
      'handler' => 'views_handler_field', 
      'click sortable' => TRUE, 
     ), 
     'sort' => array(
      'handler' => 'views_handler_sort', 
     ), 
     'filter' => array(
      'handler' => 'views_handler_filter_string', 
     ), 
     'argument' => array(
      'handler' => 'views_handler_argument_string', 
     ), 
    ); 

    // timestamp: The time of the download. 
    $data['filefield_stats']['timestamp'] = array(
     'title' => t('Download Time'), 
     'help' => t('The time of the download.'), 
     'field' => array(
      'handler' => 'views_handler_field_date', 
      'click sortable' => TRUE, 
     ), 
     'sort' => array(
      'handler' => 'views_handler_sort_date', 
     ), 
     'filter' => array(
      'handler' => 'views_handler_filter_date', 
     ), 
    ); 

    return $data; 
} // filefield_stats_views_data() 

Theo tài liệu Views2, điều này sẽ hoạt động ở mức tối thiểu, tôi nghĩ vậy. Nhưng nó không! Ngoài ra không có lỗi của bất kỳ loại nào, khi tôi đi qua giao diện người dùng quan điểm, không có gì về dữ liệu filefield_stats. Bất kỳ ý tưởng?

Trả lời

3

Tôi nghĩ rằng sự cố của bạn có trong tên hàm: hook_views_data(), nó phải là filefield_stats_views_data(). hook_views_api() cũng phải là filefield_stats_views_api().

Bạn luôn thay thế móc bằng tên mô-đun của mình khi triển khai chúng trong mô-đun của riêng bạn.

+0

không, trong nguồn mô-đun, tên móc là chính xác. lỗi chính tả, khi tôi viết câu hỏi. Tôi sẽ cập nhật câu hỏi, cảm ơn bạn. – sepehr

+0

oops, xin lỗi sau đó: p. Bạn đã thử xóa bộ nhớ cache chưa? Kiểm tra lại các bảng? – Januz

+0

có, tôi đã xóa sạch, gỡ cài đặt/cài đặt lại mô-đun & vẫn không có gì. Trong thực tế, tôi sẽ truy vấn bảng filefield_stats thông qua Drupal db api, tiếc là tôi không còn thời gian để đấu tranh với điều này nữa. cám ơn bạn một lần nữa. – sepehr