CodeIgniter - creating default object from empty value
A PHP Error was encountered
Severity: Warning
Message: Creating default object from empty value
Filename: models/Modeltest.php
Line Number: 13
I'm trying to create an array in the model and return it to the controller, but is it giving this warning? Can any body help me decide how to solve it?
My ModelClass code
$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;
Contoller class code
$this->load->model("modeltest");
print_r($this->modeltest->get_articles_list());
+3
source to share
1 answer
I believe you want something like this:
$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";
But why not use an array like an array?
$list = array();
$list[0]['title'] = "first blog title";
$list[0]['author'] = "author 1";
+8
source to share