2011-05-11 56 views
0

基本上我想創建一個自定義處理程序來反序列化一個名爲birthday的db字段。無法爲Views2創建自定義處理程序

我已經設法正確輸出使用默認views_handler_field序列化的字段。不幸的是,當我嘗試創建自定義處理程序時,我收到以下消息:

錯誤:drappsprofiles處理程序>生日不存在!

這裏的文件結構:

all/modules/drapps/drappsprofile/ 
    |->drappsprofiles.views.inc 
    |->drappsprofiles.module 
    |->drappsprofiles.install 
    |->drappsprofiles.info 
    |->drappsprofiles.inc 
    |->drappsprofiles_handler_field_birthday.inc 

這裏的drappsprofiles.module

/** 
* VIEWS2 MODULE 
* Implementation hook_views_api 
**/ 
function drappsprofiles_views_api() { 
    $info['api'] = 2; 
    return $info; 
} 

/***************************************************************************** 
*         INCLUDES 
**/ 
    // Loads Google Apps Profile Integration 
    module_load_include('inc', 'drappsprofiles'); 
(...) 

這裏的drappsprofiles.views.inc

/** 
* 
* Implementation of hook_views_handlers(). 
* 
**/ 
function drappsprofiles_views_handlers() { 
    return array(
    'handlers' => array(
     'drappsprofiles_handler_field_birthday' => array(
     'parent' => 'views_handler_field', 
    ) 
    ) 
); 
} 



/** 
* Implementation of hook_views_data(). 
* 
* @return array 
**/ 
function drappsprofiles_views_data() { 

(...) 
    $data['drappsprofiles']['birthday'] = array(
      'title' => t('Birthday'), 
      'help' => t('Users birthday'), 
      'field' => array(
       'handler' => 'drappsprofiles_handler_field_birthday', 
       'click sortable' => FALSE, 
      ), 
    ); 
    return $data; 
} 

drappsprofiles_handler_field_birthday.inc

<?php 
/** 
* 
* Custom views handler for Birthday 
* 
*/ 
class drappsprofiles_handler_field_birthday extends views_handler_field { 

    function render($values) { 

    $val = unserialize($values->{$this->field_alias}); 

    return ($val); 
    } 
} 

似乎drappsprofiles_handler_field_birthday.inc沒有被讀取,但我無法弄清楚爲什麼。

任何幫助,將不勝感激。 (我一直在圍繞這2個星期!)

回答

1

假設在.views.inc您(...)掩蓋了如下代碼:

$data['drappsprofiles']['table']['group'] = t('drappsprofiles'); 
    $data['drappsprofiles']['table']['base'] = array(
    'field' => 'birthday', 
    ); 
    $data['drappsprofiles']['table']['join'] = array(
    '#global' => array(), 
); 

我是這樣假設它確實因爲您的欄位從該組選擇,以便它可以查找丟失的處理..

然後看看接下來的事情仍然在.views.inc在module_views_handlers(){:

return array(
++ 'info' => array(
++ 'path' => drupal_get_path('module','drappsprofilse'), 
++ ), 
    'handlers' => array(

與超越那個,我h吃了說,但卸載並重新安裝模塊顯然刷新了最新的代碼調整到.views.inc ..我知道我不得不一堆,你可能也注意到了這一點。

+0

感謝您的回答。我剛纔解決了這個問題,就像你提出的那樣,卸載並重新安裝。奇怪,但它的工作。 – Tivie 2011-06-05 22:15:51

相關問題