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']

「本体」と「und」は配列であり、配列構文 ([]) でアクセスする必要があります。

これらの値に直接アクセスすることは、drupal では嫌われることがあります。調べてみるとよいかもしれません: http://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_render/7

于 2013-01-15T18:45:25.717 に答える