0

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.

Edited by chozokennedy: add content

3
Contributors
2
Replies
16
Views
4 Years
Discussion Span
Last Post by diafol
0

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

Check this link Click Here.

Edited by Bachu: text correction

0

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; ?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.