Codeigniter - 使用edit_unique编辑表单(重新填充) [英] Codeigniter - edit form (repopulating) with edit_unique

查看:163
本文介绍了Codeigniter - 使用edit_unique编辑表单(重新填充)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎 edit_unique 函数描述 here - 在CodeIgniter更新记录时验证唯一性 ,杀死 set_value 函数。

It seems that the edit_unique function, which is desribed here - Validating Uniqueness In CodeIgniter When Updating A Record, kills the set_value function.

一切正常,这样的...

All works fine, which something like this...

echo form_input('username', set_value('username',$user->username));

但是当使用 edit_unique 验证时,值在提交表单后为空。后变量是确定的,验证也没有错误 - 但是值没有设置。

But when using the edit_unique validation, the value is empty after submitting the form. Post-Variables are ok and also the validation has no errors - but the value is not set.

任何想法如何解决这个问题?

Any idea how I can fix that?

推荐答案

发现它自己。在beeing true的情况下没有返回值。也许任何人都面临同样的问题...用这个函数,它的工作原理:

Ok - found it myself. There was no return value in case of beeing true. Perhaps anyone faces the same problem... with this function, it works:

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

这篇关于Codeigniter - 使用edit_unique编辑表单(重新填充)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆