print_r($ a)的结果是
views_handle_field_node Object
(
[view]=>view Object
(
[db_table] => views_view
[base_table] => node
[args] => Array
(
[0] => My entry 1
)
[use_ajax] =>
[result] => Array
(
[0] => stdClass Object
(
[nid] => 5
[node_title] => Title of a test entry
[node_revisions_body] =>
[node_revisions_format] => 1
[node_vid] => 5
[term_data_name] => My first test term name
[term_data_vid] => 1
[term_data_tid] => 1
[vocabulary_name] => Vocabulary 1
[node_revisions_vid] => 5
)
[1]=> stdClass Object
(
[nid] => 8
[node_title] => Title of a test entry
[node_revisions_body] =>
[node_revisions_format] => 1
[node_vid] => 5
[term_data_name] => My first test term name
[term_data_vid] => 1
[term_data_tid] => 1
[vocabulary_name] => Vocabulary 1
[node_revisions_vid] => 5
..
[2]..
..
如何使用一个变量的名称来输出[nid] => 5和[nid] => 8 .....并且所有nid.i都使用它,但是无法工作。
$ views_handle_field_node-> $视图 - > $导致[] - > NID
答案 0 :(得分:1)
变量名称为$a
而非`$ views_handle_field_node',请尝试:
$first = $a->view->result[0]->nid;
//access all of the results?
foreach ($a->view->result as $obj) {
//do something with $obj->nid;
}
如果这没有用,那么告诉我们上下文是什么?您是将此代码放在模块挂钩还是模板文件中?我那种情况下是什么类型的视图设置。告诉我们“风格”和“行式”。
答案 1 :(得分:0)
$first = $views_handle_field_node->view->result[0]->nid;
//access all of the results?
foreach ($views_handle_field_node->view->result as $obj) {
//do something with $obj->nid;
}