0

我正在尝试访问 php 对象中的数据。我对确切的 stynax 是什么感到困惑。这是对象的输出:

stdClass Object ( [vid] => 10 [uid] => 1 [title] => Beachhead Don [log] => 
[status] =>  1 [comment] => 1 [promote] => 0 [sticky] => 0 [ds_switch] => [nid] => 
10 [type] => product [language] => und [created] => 1357668665 [changed] => 1358198386 
[tnid] => 0 [translate] => 0 [revision_timestamp] => 1358198386 [revision_uid] => 1  
[model] => B 3000 [list_price] => 0.00000 [cost] => 0.00000 [sell_price] => 1.00000 
[weight] => 0 [weight_units] => lb [length] => 0 [width] => 0 [height] => 0 
[length_units] => in [pkg_qty] => 1 [default_qty] => 1 [unique_hash] => 
2eec0fcc8483f3a3541870fb24223296 [ordering] => 0 [shippable] => 0 [price] => 1.00000 
[body] => Array ( [und] => Array ( [0] => Array ( [value] => Description info 
))))))))))))))))))))))))))))))))))))))0 [summary] => [format] => filtered_html 
[safe_value] =>Description info ))))))))))))))))))))))))))))))))))))))0[safe_summary] 
=> ) ) ) [uc_product_image] => Array ( [und] => Array ( [0] => Array ( [fid] => 11 
[alt] => [title] => [width] => 90 [height] => 120 [uid] => 1 [filename] => 
beachhead_don.jpg [uri] => public://beachhead_don.jpg [filemime] => image/jpeg 
[filesize] => 14342 [status] => 1 [timestamp] => 1357668665 [rdf_mapping] => Array ( ) 
) ) ) [field_author] => Array ( [und] => Array ( [0] => Array ( [value] => John B. 
Romesier [format] => [safe_value] => John B. Romesier ) ) ) [field_publisher] => Array 
( [und] => Array ( [0] => Array ( [value] => Unknown [format] => [safe_value] => 
Unknown ) ) ) [field_release_date] => Array ( [und] => Array ( [0] => Array ( [value] 
=> Mar 2012 [format] => [safe_value] => Mar 2012 ) ) ) [field_number_of_pages] => Array 
( [und] => Array ( [0] => Array ( [value] => 123 ) ) ) [field_catagory] => Array ( 
[und] => Array ( [0] => Array ( [tid] => 4 ) ) ) [field_book_type] => Array ( [und] => Array ( [0] => Array ( [tid] => 1 ) ) ) [field_isbn] => Array ( ) [field_about_the_author] => Array ( [und] => Array ( [0] => Array ( [value] => Beachhed Don authoer............................ [format] => [safe_value] => Beachhed Don authoer............................ ) ) ) [rdf_mapping] => Array ( [rdftype] => Array ( [0] => sioc:Item [1] => foaf:Document ) [title] => Array ( [predicates] => Array ( [0] => dc:title ) ) [created] => Array ( [predicates] => Array ( [0] => dc:date [1] => dc:created ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [changed] => Array ( [predicates] => Array ( [0] => dc:modified ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [body] => Array ( [predicates] => Array ( [0] => content:encoded ) ) [uid] => Array ( [predicates] => Array ( [0] => sioc:has_creator ) [type] => rel ) [name] => Array ( [predicates] => Array ( [0] => foaf:name ) ) [comment_count] => Array ( [predicates] => Array ( [0] => sioc:num_replies ) [datatype] => xsd:integer ) [last_activity] => Array ( [predicates] => Array ( [0] => sioc:last_activity_date ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) ) [cid] => 0 [last_comment_timestamp] => 1357668665 [last_comment_name] => [last_comment_uid] => 1 [comment_count] => 0 [name] => admin [picture] => 0 [data] => b:0; [entity_view_prepared] => 1 )

我正在尝试检索描述信息的[值] ))))))))))))))))))))))))))))))))))))))))))))))))))) 0

我试过这个

<?php
$node = menu_get_object();  //drupal code
if ( !empty($node) ) {
print $node ->body=>und=>0=>value;

}?>

并收到有关“=”符号的错误。获取我的数据的正确方法是什么?

4

2 回答 2

2

[body]并且[und]是数组,所以像这样访问它们:

echo $node->body['und'][0]['value'];
于 2013-01-15T18:43:48.123 回答
0

应该是:$node->body['und'][0]['value']

'Body' 和 'und' 是数组,需要使用数组语法([])访问。

在 drupal 中,有时不赞成直接访问这些值。您可能想查看:http ://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_render/7

于 2013-01-15T18:45:25.717 回答