A PHP Error was encountered
Severity: Warning
Message: Creating default object from empty value
Filename: models/Modeltest.php
Line Number: 13
我试图在模型中创建一个数组并将其返回给控制器,但它是否给出了这个警告?任何人都可以帮我解决问题吗?
我的ModelClass代码
$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;
我的控制器类代码
$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";