gpt4 book ai didi

php - CodeIgniter is_unique 语言文件中的错误消息

转载 作者:可可西里 更新时间:2023-11-01 13:30:18 24 4
gpt4 key购买 nike

当使用 CodeIgniter 时,我喜欢在 application/language/english/form_validation_lang.php 中设置我的错误消息,这对每条错误消息都有效,但似乎不适用于 is_unique 消息,因为它给了我“电子邮件字段必须包含唯一值”的标准消息。

我的代码:

$lang['is_unique'] = "输入的 %s 已被使用。";

最佳答案

创建一个名为 form_validation_lang.php 的文件,如下所示

  • application/language/english/form_validation_lang.php

到system/language/english/form_validation_lang.php找到。

$lang['form_validation_is_unique'] = 'The {field} field must contain a unique value.';

复制上面的键然后添加到application/language/english/form_validation_lang.php

$lang['form_validation_is_unique'] = 'The {field} entered is already in use.';

下一步

在 Controller 表单验证添加

$this->lang->load('form_validation', 'english');

喜欢

$this->lang->load('form_validation', 'english');
$this->form_validation->set_rules('username', 'Username', 'trim|required|is_unique[users.username]');

注意:如果您在其他 Controller 中使用 form_validation is_unique 并且想要使用该消息,您将需要加载此 $this->lang->load('form_validation', ' english'); 除非您选择自动加载它,否则也会加载到该 Controller 上。

关于php - CodeIgniter is_unique 语言文件中的错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30528527/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com