关于Drupal的数据表查看

2017-09-13 20:35:29来源:CSDN作者:susjoy人点击

分享

在很多时候我们协同开发,首先需要做的就是对数据表结构做了解,而处于某些原因不能直接分享数据库账号密码,所以做了这么一个功能来查看表结构;
该表结构显示的是基于Drupal的开发,前端利用bootstrap来友好显示。
下面贴出theme后台代码:

    function bns_preprocess_html__main(array &$variables){        $entityManager = Drupal::service('entity.manager');        $contentTypes = $entityManager->getStorage('node_type')->loadMultiple();        $contentTypesList = [];        foreach ($contentTypes as $k => $contentType) {           $contentTypesList[$k]['title'] = $contentType->id() . '(' . $contentType->label() . ')';           $contentTypesList[$k]['id'] = $contentType->id();           $fields = array_filter(               $entityManager->getFieldDefinitions('node', $contentType->id()), function ($field_definition) {                   return $field_definition instanceof /Drupal/Core/Field/FieldConfigInterface;               }           );           foreach ($fields as $k1 => $v1) {                 $contentTypesList[$k]['fields'][$k1]['name'] = $k1;               $contentTypesList[$k]['fields'][$k1]['des'] = $v1->getDescription();               $contentTypesList[$k]['fields'][$k1]['field_type'] = $v1->getType();               $contentTypesList[$k]['fields'][$k1]['label'] = $v1->getLabel();           }        }        $variables['content_types'] = $contentTypesList;    }

前端页面的显示:

  1. 引入资源(cdn资源,可能会遇到404情况):
    <link href="//cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">    <script src="//cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>    <script src="//cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  1. html结构
<body>    <div class="panel-group" id="accordion">        <span class="label label-success">程序结构</span>        {% for content_type in content_types %}          <div class="panel panel-default">              <div class="panel-heading">                  <h4 class="panel-title">                      <a data-toggle="collapse" data-parent="#accordion"                         href="#{{ content_type.id }}">                          {{ content_type.title }}                      </a>                  </h4>              </div>              <div id="{{ content_type.id }}" class="panel-collapse collapse">                  <div class="panel-body">                            <table class="table">                          <thead>                          <tr>                              <th>名称</th>                              <th>label</th>                              <th>类型</th>                              <th>描述</th></tr>                          </thead>                          <tbody>                          {% for field in content_type.fields %}                          <tr class="active">                              <td>{{ field.name }}</td>                              <td>{{ field.label }}</td>                              <td> {{ field.field_type }}</td>                              <td>{{ field.des }}</td></tr>                          {% endfor %}                          </tbody>                      </table>                  </div>              </div>          </div>        {% endfor %}    </div></body>

好了,基本到此为止,然后我们来看看效果吧
冰山一角

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台