【问题标题】:Codeigniter Edit Error -> Call to undefined methodCodeigniter 编辑错误 -> 调用未定义的方法
【发布时间】:2016-10-05 03:49:50
【问题描述】:

遇到 PHP 错误
严重性:错误
消息:调用未定义的方法 Post::where()
文件名: models/post.php
行号: 23

这是我的编辑控制器

function editpost($postID){
    $data['success']=0;
    if($_POST){
        $data_post=array(
            'title'=>$_POST['title'],
            'post'=>$_POST['post'],
            'active'=>1
        );
        $this->post->update_post($postID,$data_post);
        $data['success']=1;
    }
    $data['post']=$this->post->get_post($postID);
    $this->load->view('edit_post',$data);
}

这是我的更新模型

function update_post($postID,$data){
        $this->where('postID',$postID);
        $this->db->update('posts',$data);
    }

我更改了data_post - 数据相同的错误

我的错误在哪里?

【问题讨论】:

  • 在你的模型函数update_post中发现了一个小错误。用db代替$this->db->where('postID' ,$postID);

标签: php codeigniter frameworks


【解决方案1】:

在您的型号代码中输入$this->db->where('postID',$postID); $this->db->update('posts',$data)

【讨论】:

    【解决方案2】:

    如下代码:

    function update_post($postID,$data){
        $this->db->where('postID',$postID);
        $this->db->update('posts',$data);
    }
    

    请将您的update_post 功能代码从$this->where('postID',$postID); 更改为 到$this->db->where('postID',$postID);。您在模型页面中缺少->db 之前的->where 条件。

    谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-03
      • 1970-01-01
      • 2020-09-22
      • 2016-05-08
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多