Hello, I'm getting a error : Trying to get property of non-object. Currently using CodeIgniter php framework.

Controller:

public function index() {
        $this->load->model('data_model');
        $data['rows'] = $this->data_model->getAll();

        $this->load->view('index',$data);
    }

Views:

 <?php foreach($rows as $r) : ?>
        <h1><?php echo $r->title; ?></h1> //Error on this line
        <div><?php echo $r->contents; ?></div> //Error on this line

<?php endforeach; ?>

Thanks You.

I think, You assign the result to an array, and you try to use the array as an object.

Check this link Click Here.

Member Avatar

diafol

Haven't used CI in a long while, but isn't it...

<?php foreach($data['rows'] as $r) : ?>
        <h1><?php echo $r->title; ?></h1> //Error on this line
        <div><?php echo $r->contents; ?></div> //Error on this line
<?php endforeach; ?>