【问题标题】:simple mysql query to access data fields in Drupal 7访问 Drupal 7 中数据字段的简单 mysql 查询
【发布时间】:2015-10-12 20:42:44
【问题描述】:

我在使用 Drupal 7 时遇到了一些问题。我想做的是用 php 读取一个对象的所有 field_data_fields。

示例:我需要显示 CAR 条目并且我需要访问 field_data_field_speed field_data_field_size

等等

问题是我无法找出所有这些字段条目都连接到对象 ID 的位置。是否有一个非常简单的解决方案可以让所有字段都连接到一个对象 ID?

任何了解 Drupal 并且可以帮助我的人? :) 谢谢

【问题讨论】:

    标签: php mysql drupal drupal-7


    【解决方案1】:

    听起来像 EntityFieldQuery 应该可以为您节省大量时间

    编辑:添加您可以参考的示例

    $query = new EntityFieldQuery();
    
    $query
      ->entityCondition('entity_type', 'node')
      ->entityCondition('bundle', 'car')
      ->propertyCondition('status', 1); //Remove to include unpublished content
    $result = $query->execute();
    
    $nids = array_keys($result['node']);
    
    if(!empty($nids)){
    
        $nodes = node_load_multiple($nids);
    
        foreach($node as $car_node){
            $node_wrapper = entity_metadata_wrapper('node', $car_node);
    
            //FINALLY! Here we can get the value of the field you need
            $size = $node_wrapper->field_size->value();
    
        }
    }
    

    【讨论】:

      【解决方案2】:

      使用“视图”模块比编写自己的查询要容易得多。比如说,它是 Drupal 开发的标准:

      https://www.drupal.org/project/views

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多