【问题标题】:Cannot use object of type stdClass as array in CodeIgniter不能在 CodeIgniter 中使用 stdClass 类型的对象作为数组
【发布时间】:2014-03-26 09:31:53
【问题描述】:

我正在尝试在表格中显示输入,但我的代码生成以下错误:

Fatal error: Cannot use object of type stdClass as array in line 36

这是我的看法:

<tbody>
                                <?php
                                    $no=1;
                                    if ($berita){
                                    foreach ($berita as $dt) {
                                        echo "
                                            <tr>
                                                <td>$dt[id_berita]</td> (line 36)
                                                <td>$dt[tanggal]</td>
                                                <td>$dt[judul_berita]</td>
                                                <td>$dt[content]</td>
                                                <td><a class='ui tiny blue edit button' href='".base_url()."index.php/admin/berita/edit/$dt[id_berita]'><i class='edit icon'></i></a>
                                                <a class='ui tiny blue edit button' href='".base_url()."index.php/admin/berita/delete/$dt[id_berita]'><i class='trash icon'></i></a></td>

                                            </tr>
                                        ";
                                        $no++;
                                    }
                                    }
                                ?>

                            </tbody>

我的代码有什么问题?

【问题讨论】:

    标签: arrays codeigniter object view stdclass


    【解决方案1】:

    如果 $dt 是对象,那么你可以如下所示

    $dt->id_berita
    $dt->tanggal
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-17
      • 2012-01-19
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多