Php Codeigniter-编辑表单(重新填充),具有唯一的编辑功能

Php Codeigniter-编辑表单(重新填充),具有唯一的编辑功能,php,codeigniter,validation,codeigniter-form-helper,Php,Codeigniter,Validation,Codeigniter Form Helper,似乎所描述的edit_unique函数终止了set_value函数 一切都很好,就像这样 echo form_input('username', set_value('username',$user->username)); 但是当使用edit_unique验证时,提交表单后该值为空。Post变量正常,并且验证没有错误-但未设置值 知道我该怎么解决吗?好的-我自己找到的。如果为true,则没有返回值。也许任何人都面临同样的问题。。。使用此功能,它可以: function edit_uni

似乎所描述的
edit_unique
函数终止了
set_value
函数

一切都很好,就像这样

echo form_input('username', set_value('username',$user->username));
但是当使用
edit_unique
验证时,提交表单后该值为空。Post变量正常,并且验证没有错误-但未设置值


知道我该怎么解决吗?

好的-我自己找到的。如果为true,则没有返回值。也许任何人都面临同样的问题。。。使用此功能,它可以:

function edit_unique($value, $params)  {
    $CI =& get_instance();
    $CI->load->database();

    $CI->form_validation->set_message('edit_unique', "Sorry, that %s is already being used.");

    list($table, $field, $current_id) = explode(".", $params);

    $query = $CI->db->select()->from($table)->where($field, $value)->limit(1)->get();

    if ($query->row() && $query->row()->id != $current_id)
    {
        return FALSE;
    } else {
        return TRUE;
    }
}

佩特拉的答案很有效,如果出于某种原因,它对你不起作用,请检查你的主键是否为“id”,如果不是,你需要做一些更改

改变

list($table,$field,$current_id)=分解(“.”,$params);
如果($query->row()&&&$query->row()->id!=$current\u id)

list($table,$field,$current_id,$key)=分解(“.”,$params);
如果($query->row()&&&$query->row()->$key!=$current\u id)
然后添加如下规则:

$this->表单验证->设置规则(
“form_字段”,
“表格标签”,
“必需的|修剪|编辑|唯一[表.列..$edit..unique]”
);

其中,
unique
是您的唯一/主键,
$edit
是它的值。

edit\u unique
用法可在