繁体   English   中英

从php对象检索数据

[英]retrieving data from a php object

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

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 )

我试图检索描述信息的[value]))))))))))))))))))))))))))))))))))))))))))) 0

我试过了

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

}?>

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

[body][und]是数组,因此请按以下方式访问它们:

echo $node->body['und'][0]['value'];

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

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

在drupal中有时不愿直接访问这些值。 您可能需要调查: http : //api.drupal.org/api/drupal/includes%21common.inc/function/drupal_render/7

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM