drupal视图---如何输出

发布于 2024-10-05 17:08:59 字数 1485 浏览 0 评论 0原文

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->$view->$result[]->nid

the print_r($a)'s result is

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

how to use one variable's name to out put the [nid]=>5 and[nid]=>8.....and all the nid.i use this, but can't work.

$views_handle_field_node->$view->$result[]->nid

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

在梵高的星空下 2024-10-12 17:09:24
$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;
}
$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;
}
够钟 2024-10-12 17:09:20

变量名称是 $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;
}

如果这没有帮助,那么告诉我们上下文是什么?您是否将此代码放入模块挂钩或模板文件中?我这种情况需要什么类型的视图设置。告诉我们“样式”和“行样式”。

The variables name is $a not `$views_handle_field_node' so try:

$first = $a->view->result[0]->nid;

//access all of the results?
foreach ($a->view->result as $obj) {
    //do something with $obj->nid;
}

If that doesn't help then tell us what is the context? Are you putting this code inside a module hook or a template file? I that case what type of view settings. Tell us the "Style" and "Row style".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文