无法为 Views2 创建自定义处理程序

发布于 2024-11-06 00:30:16 字数 2083 浏览 5 评论 0原文

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

我已经成功地使用默认的views_handler_field正确输出序列化的字段。不幸的是,当我尝试创建自定义处理程序时,我收到此消息:

Error: handler for 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 没有被读取,尽管我不明白为什么。

任何帮助将不胜感激。 (我已经解决这个问题两周了!)

Basically I want to create a custom handler to unserialize a db field called birthday.

I've managed to correctly output the field serialized using the default views_handler_field. Unfortunately When I try to create a custom handler, I get this message:

Error: handler for drappsprofiles > birthday doesn't exist!

Here's the file structure:

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

here's 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');
(...)

here's 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);
  }
}

It seems that drappsprofiles_handler_field_birthday.inc is not being read, although I can't figure out why.

Any help would be appreciated. (I've been around this for 2 weeks!)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

善良天后 2024-11-13 00:30:16

假设您的 (...) 在 .views.inc 中隐藏了如下代码:

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

我假设它确实如此,因为您的字段有一个组可以从中选择它,以便它可以查找丢失的处理程序..

然后下一步要查找at 仍在 module_views_handlers() { 中的 .views.inc 中:

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

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

Assuming your (...) in .views.inc conceals code like:

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

Which I am assuming it does since your field has a group from which to select it so that it can look for the missing handler..

Then the next thing to look at is still in .views.inc in module_views_handlers() { :

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

And beyond that, I hate to say it, but uninstalling and reinstalling the module apparently refreshes recent code tweaks to the .views.inc .. I know I had to a bunch of times, you probably noticed this too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文