Able to see a variable in print_r()'s output, but not sure how to access it in code

后端 未结 9 681

I googled, installed Devel, Drupal for Firebug, but I can\'t find it.

I found what I want, I know where it is; I just don\'t know how to g

相关标签:
9条回答
  • 2020-11-22 03:07

    If this is your object:

    field_image (Object) stdClass 
      handler (Object) views_handler_field_field 
        view (Object) view 
          result (Array, 2 elements) 
            0 (Object) stdClass 
              _field_data (Array, 1 element) 
                nid (Array, 2 elements) 
                  entity (Object) stdClass
                    field_image (Array, 1 element) 
                      und (Array, 1 element)
                        0 (Array, 11 elements)                                      
                          filename (String, 23 characters ) FILENAME.jpg
    

    I'd guess you can find it using:

    field_image->handler->view->result[0]->_field_data['nid'][entity]->field_image['und'][0]['filename]
    

    Could be a mistake in there, but the general Idea is: if you have an object, get the variable using ->, and if you have an array, use [key].

    0 讨论(0)
  • 2020-11-22 03:07

    You should use field_view_field($entity_type, $entity, $field_name, $display = array(), $langcode = NULL) , that will return renderable array . You can check api document https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_view_field/7.x

    0 讨论(0)
  • 2020-11-22 03:16

    If you can't use devel module for some reason, another useful "debug" functions could be var_export() and a Drupal wrapper drupal_var_export(). These functions gives the output as PHP code.

    0 讨论(0)
提交回复
热议问题