【问题标题】:Can't create custom handler for Views2无法为 Views2 创建自定义处理程序
【发布时间】:2011-05-11 01:17:06
【问题描述】:

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

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

dappsprofiles_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 周的时间了!)

【问题讨论】:

    标签: drupal drupal-modules views2


    【解决方案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 的代码调整。我知道我不得不这样做很多次,你可能也注意到了这一点。

    【讨论】:

    • 感谢您的回答。我刚才通过卸载和重新安装解决了这个问题,就像你建议的那样。奇怪,但它奏效了。
    猜你喜欢
    • 2014-04-12
    • 1970-01-01
    • 2011-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 2019-12-20
    相关资源
    最近更新 更多