dr637349 2013-06-16 03:42
浏览 29
已采纳

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;
 }
}
  • 写回答

1条回答 默认 最新

  • dtd14883 2013-06-16 03:59
    关注

    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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元