Codeigniter - 尝试获取非对象的属性

Please help with the error I'm getting in Codeigniter and grocery crud. Below code is throwing the following message and I'm stuck with it for a few days, I'm a total noob : ( Error:

A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: controllers/examples.php

Line Number: 70

ps:

Function does what it needs, but the above error shows up.

I appreciate your thoughts on this!

 function security() {
 $method = $this->uri->segment(3); //tell ci that we are working on url segment 3, e.g. delete,  update ....

if ($method == "edit" or $method == 'update_validation' or $method == 'delete') {
       $id = $this->uri->segment(4); //work on url segment 4, now pointing at posts table       primary key
        $this->db->where('posts.user_id', $this->session->userdata('id'));
        $result = $this->db->get_where('posts', array('id' => $id), 1)->row();

       //this is line: 70 if ($result->id != $id)
       {
           echo "You don't have access";
           exit;
       }
     else return true;
 }
}

You may want to add a value check to the $this->db->get_where('posts', array('id' => $id), 1)->row(); line. It seems like that line may be returning false or something if no row is available, though I can't find the exact return value in the documentation.

$result = this->db->get_where('posts', array('id' => $id), 1)->row();
if (!$result || $result->id != $id) {
  echo "You don't have access";
  exit;
}