本文介绍了错误:您必须使用“设置"方法来更新条目修复程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用codeigniter作为我的PHP框架,当我将from提交到数据库时,我一直收到此错误.

I am using codeigniter as my PHP framework, and I keep getting this error when I submit my from to post to my database.

You must use the "set" method to update an entry

从我看过的其他文章中,我不确定这意味着什么,每个人都说datamapper需要为该对象分配一个值.

I am not exactly sure what that means, from the other posts I have looked at, everyone says that the datamapper needs to have a value assigned to the object.

因为我是这一切的新手,所以有人可以给我更好的解释.

Being that I am new to all this, could someone give me a better explaniation.

这是我的代码,其中显示我有错误:

Here is my code where it says I have the error:

class Add_book extends CI_Model {

public function add_book($data){

    $this->db->insert('ST_ITM', $data);

}

}

?>

谢谢.

推荐答案

您需要执行类似此示例的操作

You need to do something like this Example Only

class Add_book extends CI_Model {

public function add_book(){

    // 'book_name' would be the name of your column in database table

    $data = array(
    'book_title' => $this->input->post('book_title'),
    'book_author' => $this->input->post('book_author'),
    'book_name' => $this->input->post('book_name')
    );

    $this->db->set($data);
    $this->db->insert($this->db->dbprefix . 'ST_ITM');

}

}

在视图上,输入类似于示例

On view the input would be like example

<input type="text" name="book_name" value="" />

<input type="text" name="book_title" value="" />

<input type="text" name="book_author" value="" />

最好在模型中使用数据数组.然后在表单验证的成功部分中加载模型函数

Best to use a data array in model. and then load model function in success part of form validation Library

这篇关于错误:您必须使用“设置"方法来更新条目修复程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 06:59