php – 将一个表暴露给Views

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了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;
}
@H_301_34@

脚本宝典总结

以上是脚本宝典为你收集整理的php – 将一个表暴露给Views全部内容,希望文章能够帮你解决php – 将一个表暴露给Views所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。