从数据字段中检索特定值

时间:2011-10-24 21:22:38

标签: drupal views

以下是我想要使用的一些视图数据。我怎么才能渲染'Lorem ipsum'?感谢

stdClass Object
(
  [nid] => 13337
  [node_data_field_marquee_image_field_marquee_image_fid] => 7778
  [node_data_field_marquee_image_field_marquee_image_list] => 1
  [node_data_field_marquee_image_field_marquee_image_data] => a:3:{s:11:"description";s:11:"Lorem ipsum";s:3:"alt";s:0:"";s:5:"title";s:0:"";}
  [node_language] => 
  [node_type] => article
  [node_vid] => 22670
  [node_data_field_marquee_url_field_marquee_url_url] => www.google.com
  [node_data_field_marquee_url_field_marquee_url_title] => 
  [node_data_field_marquee_url_field_marquee_url_attributes] => a:1:{s:6:"target";s:6:"_blank";}
)

渲染数据:

$item = unserialize($data->node_data_field_marquee_image_field_marquee_image_data);
$description = $item['description'];
print $description;

$item2 = unserialize($data->node_data_field_marquee_url_field_marquee_url_attributes);
$target = item2['target'];
print $target;

给出此错误:

解析错误:语法错误,意外'[在/sites/all/modules/contrib/views_customfield/includes/views_customfield_handler_field_phpcode.inc(118)):eval()'d代码在第9行

1 个答案:

答案 0 :(得分:0)

假设您的变量名为$node_data_field_marquee_image_field_marquee_image_data

$description = $node_data_field_marquee_image_field_marquee_image_data['description'];

<强>更新

我的错误是阵列被序列化了,你会想要这样做:

$item = unserialize($data->node_data_field_marquee_image_field_marquee_image_data);
$description = $item['description'];