2010-01-30 13 views
5

का उपयोग करके व्यू 2 में मॉड्यूल के डेटा का खुलासा करते हुए मैं filefield_stats मॉड्यूल को मॉड्यूल में API के माध्यम से डेटा को उजागर करने की क्षमता प्रदान करने के लिए मजबूर कर रहा हूं। filefield_stats स्कीमा पालन है:अपने एपीआई

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; 
} 

ठीक है, तो मैं filefield_stats.module में hook_views_api() कार्यान्वित & मॉड्यूल के रूट निर्देशिका में एक filefield_stats.views.inc फ़ाइल कहा, यहां यह है:

// $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() 

दृश्य 2 दस्तावेजों के अनुसार यह कम से कम काम करना चाहिए, मुझे लगता है। लेकिन यह नहीं है! इसके अलावा कोई भी त्रुटि नहीं है, जब मैं दृश्य यूआई के माध्यम से आती हूं, तो filefield_stats डेटा के बारे में कुछ भी नहीं है। कोई उपाय?

उत्तर

3

मुझे लगता है कि आपकी समस्या फ़ंक्शन नाम में है: hook_views_data(), यह filefield_stats_views_data() होना चाहिए। hook_views_api() भी filefield_stats_views_api() होना चाहिए।

आप हमेशा अपने मॉड्यूल नाम के साथ अपने मॉड्यूल में लागू करते समय हुक को प्रतिस्थापित करते हैं।

+0

ओह नहीं, मॉड्यूल स्रोत में, हुक नाम सही हैं। टाइपो, जब मैं सवाल लिख रहा था। मैं सवाल अपडेट करूंगा, धन्यवाद। – sepehr

+0

ओह, क्षमा करें तो: पी। क्या आपने कैश को फ्लश करने की कोशिश की? टेबल की जांच दो बार? – Januz

+0

हाँ, मैंने इसे फ्लश कर दिया है, मॉड्यूल को अनइंस्टॉल/पुनर्स्थापित किया है और अभी भी कुछ भी नहीं है। वास्तव में मैं ड्रूपल डीबी एपीआई के माध्यम से filefield_stats तालिका से पूछताछ करने जा रहा हूं, दुर्भाग्यवश मेरे पास इसके साथ संघर्ष करने का कोई और समय नहीं है। फिर से धन्यवाद। – sepehr