Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 am trying to create an array in model and returning it to the controller but it is giving this warning ? Can any body help me out how to resolve 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;

My Contoller Class Code

    $this->load->model("modeltest");
    print_r($this->modeltest->get_articles_list());
like image 503
Nisar ahmed Avatar asked Jan 09 '23 08:01

Nisar ahmed


1 Answers

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 using the array as an array?

$list = array();
$list[0]['title'] = "first blog title";
$list[0]['author'] = "author 1";
like image 128
Damien Pirsy Avatar answered Jan 25 '23 13:01

Damien Pirsy