0

请帮助解决我在 Codeigniter 和杂货店中遇到的错误。下面的代码抛出以下消息,我坚持了几天,我完全是菜鸟:(错误:

遇到 PHP 错误

严重性:通知

消息:试图获取非对象的属性

文件名:控制器/examples.php

行号:70

ps:

函数做它需要的,但是上面的错误出现了。

我很欣赏你对此的想法!

 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;
 }
}
4

1 回答 1

0

您可能希望向该$this->db->get_where('posts', array('id' => $id), 1)->row();行添加值检查。false尽管我在文档中找不到确切的返回值,但似乎该行可能正在返回或如果没有可用的行。

$result = this->db->get_where('posts', array('id' => $id), 1)->row();
if (!$result || $result->id != $id) {
  echo "You don't have access";
  exit;
}
于 2013-06-16T03:59:02.493 回答