0

基本上我想创建一个自定义处理程序来反序列化一个名为生日的数据库字段。

我已经设法正确输出使用默认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 周!)

4

1 回答 1

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(

除此之外,我不想这么说,但卸载和重新安装模块显然会刷新最近对 .views.inc 的代码调整。我知道我不得不这样做很多次,你可能也注意到了这一点。

于 2011-06-04T21:24:28.510 回答