加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 将一个表暴露给Views

发布时间:2020-12-13 21:38:21 所属栏目:PHP教程 来源:网络整理
导读:我有一个由模块创建的表.我需要将其中的一些字段包含在现有视图中. 我尝试使用the table wizard module,但它只是为该表创建一个单独的视图.我希望能够从该表中选择要添加到现有视图中的字段作为附加字段,或通过关系或类似的东西.是否有解决方法来做我想做的
我有一个由模块创建的表.我需要将其中的一些字段包含在现有视图中.

我尝试使用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;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读