php – 将一个表暴露给Views

我有一个由模块创建的表.我需要将其中的一些字段包含在现有视图中.

我尝试使用the table wizard module,但它只是为该表创建一个单独的视图.我希望能够从该表中选择要添加到现有视图中的字段作为附加字段,或通过关系或类似的东西.是否有解决方法来做我想做的事情?

解决方法:

啊.视图.我也花了一段时间.这个答案适用于Drupal 6,并在摘要中展示了如何定义字段以及使用关系来允许字段链接到节点表.

在modulename.module里面,你需要一个函数

function modulename_views_api() {
  return array(
    'api' => 2,
  );
}

然后你想创建一个名为modulename.views.inc的文件并定义一个这样的函数

function modulename_views_data() {
    $data['modulename_table'] = array(
        'table'     => array(
            'group'     => 'ModuleName',
            'title'     => 'Module name title',
        ),
        'join'  =>  array(
            // to join to node, we'll use a field in modulename_table called 'nid'
            'node'      => array(
                'left_field'    =>  'nid',
                'field'         =>  'nid',
            ),
        ),
    );

    // Now we define the fields in the table like this
    // check out modules/views/handlers to see more specific handlers

    $data['modulename_table']['fieldname'] = array(
        'title'     => 'fieldname',
        'help'      => 'fieldname description',
        'field'    => array(
            'handler' => 'views_handler_field',
        ),
    );

    $data['modulename_table']['nid'] = array(
        'title'     => 'related node',
        'help'      => 'the field that relates back to {node}',
        // here we implement a relationship to nid
        'relationship'  => array(
            'base'      => 'node',
            'field'     => 'nid',
            'handler'   => 'views_handler_relationship',
            'label'     => 'modulename row node',
        ),
        // this relationship can be turned on in views
    );

    return $data;
}

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...