gpt4 book ai didi

php - CodeIgniter - 从空值创建默认对象

转载 作者:可可西里 更新时间:2023-11-01 00:08:56 24 4
gpt4 key购买 nike

A PHP Error was encountered

Severity: Warning

Message: Creating default object from empty value

Filename: models/Modeltest.php

Line Number: 13

我正在尝试在模型中创建一个数组并将其返回给 Controller ,但它给出了这个警告?任何人都可以帮我解决这个问题吗?

我的模型类代码

    $list = Array();
$list[0]->title = "first blog title";
$list[0]->author = "author 1";

$list[1]->title = "second blog title";
$list[1]->author = "author 2";

return $list;

我的 Controller 类代码

    $this->load->model("modeltest");
print_r($this->modeltest->get_articles_list());

最佳答案

我相信你想要这样的东西:

$list = array();
$list[0] = new stdClass;
$list[0]->title = "first blog title";
$list[0]->author = "author 1";
$list[1] = new stdClass;
$list[1]->title = "second blog title";
$list[1]->author = "author 2";

但是为什么不把数组当作数组来使用呢?

$list = array();
$list[0]['title'] = "first blog title";
$list[0]['author'] = "author 1";

关于php - CodeIgniter - 从空值创建默认对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27217554/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com