2011-05-11 57 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

相关问题