我試圖在Drupal 7安裝中打印值爲「Viviana」的值,這個值在配置文件節點內的某處。我想要的是打印輸出用戶名的字段內容。如何打印其他數組內的數組內的內容?
從來就試過這個選項,但從來就得到了錯誤:print $field_nombrecompleto1['und'][0]['value'];
The error was Notice: Undefined variable: field_nombrecompleto1 in /home/liga/public_html/sites/all/themes/liga/templates/user-profile.tpl.php on line 7
I'm使用print_r的發佈後的輸出(一點點縮短)()。
感謝您的幫助!在你的輸出
Array
(
[template_file] => sites/all/themes/liga/templates/user-profile.tpl.php
[variables] => Array
(
[elements] => Array
(
[#pre_render] => Array
(
[0] => _field_extra_fields_pre_render
[1] => field_group_build_pre_render
)
[#entity_type] => user
[#bundle] => user
[#groups] => Array
(
)
[#fieldgroups] => Array
(
)
[#group_children] => Array
(
)
[#theme] => user_profile
[#account] => stdClass Object
(
[uid] => 78
[name] => milne
[pass] => U$S$9B.hwxhcWeayArrP8Y/qsNXj9SNMh6z5FaCjAebOq1UrYbQJ/uIR
[mail] => [email protected]
[theme] =>
[signature] =>
[signature_format] => 3
[created] => 1157654988
[access] => 1185380339
[login] => 1185380321
[status] => 1
[timezone] =>
[language] => es
[picture] =>
[init] => [email protected]
...
...
...
[#view_mode] => full
[#language] => es
[#block] => stdClass Object
(
[module] => system
[delta] => main
[theme] => liga
[status] => 1
[weight] => -53
[region] => content
[custom] => 0
[visibility] => 0
[pages] =>
[title] =>
[bid] => 2154
[cache] => -1
[subject] =>
)
[#weight] => -53
[#theme_wrappers] => Array
(
[0] => block
)
...
...
...
[profile_alumnos] => Array
(
[#type] => user_profile_category
[#title] => Perfil Alumnos
[#prefix] =>
[view] => Array
(
[profile2] => Array
(
[5] => Array
(
[field_nombrecompleto1] => Array
(
[#theme] => field
[#weight] => 0
[#title] => nombrecompleto1
[#access] => 1
[#label_display] => hidden
[#view_mode] => account
[#language] => und
[#field_name] => field_nombrecompleto1
[#field_type] => text
[#field_translatable] => 0
[#entity_type] => profile2
[#bundle] => alumnos
[#object] => Profile Object
(
[pid] => 5
[type] => alumnos
[label] => Perfil Alumnos
[uid] => 78
[created] => 1358457398
[changed] => 1358457398
[entityType:protected] => profile2
[entityInfo:protected] => Array
(
[label] => Profile
[plural label] => Profiles
[description] => Profile2 user profiles.
[entity class] => Profile
[controller class] => EntityAPIController
[base table] => profile
[fieldable] => 1
...
...
...
[field_nombrecompleto1] => Array
(
[und] => Array
(
[0] => Array
(
[value] => Viviana
[format] =>
[safe_value] => Viviana
)
)
)
[field_cursobasico1] => Array
(
)
[field_telefonos1] => Array
(
)
[field_zona1] => Array
(
)
[entity_view_prepared] => 1
)
[#items] => Array
(
[0] => Array
(
[value] => Viviana
[format] =>
[safe_value] => Viviana
)
)
...
...
錯誤已經足夠清楚了:變量'field_nombretopleto1'不存在。你確定你是print_r'ing正確的變量? –
是的,這就是爲什麼我不明白... – Rosamunda
可能重複[遞歸php函數,將嵌套數組轉換爲嵌套的html塊](http://stackoverflow.com/questions/1766995/recursive-php-function -that-turns-nested-array-into-nested-html-blocks) –