2

在一个表单中,我有一个回调函数来检查一个数字是否可用。如果返回 TRUE,则显示错误消息。

回调正在工作,但它显示: lang:shortcodes.not_unique 而不是单独文件中给出的内容。

我不知道出了什么问题,也没有在用户指南中找到相关内容。

感谢您的帮助。

public function __construct()
{
    parent::__construct();

    // Load all the required classes
    $this->load->model('shortcodes_m');
    $this->load->library('form_validation');
    $this->lang->load('shortcodes');

    // Set the validation rules
    $this->item_validation_rules = array(
        array(
            'field' => 'number',
            'label' => 'lang:shortcodes.number',
            'rules' => 'trim|max_length[100]|required|numeric'
        ),
        array(
            'field' => 'name',
            'label' => 'lang:shortcodes.name',
            'rules' => 'trim|max_length[100]|required|callback_shortcodes_check'
        )
    );

}
public function shortcodes_check($str)
{
    if($this->shortcodes_m->is_available($str) == TRUE)
    {
        $this->form_validation->set_message('shortcodes_check','lang:shortcodes.not_unique');
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}
4

1 回答 1

2

您需要从语言文件中获取该行。文档没有提到能够通过该set_message()方法使用字段名称翻译。采用:

$this->lang->line('not_unique');
于 2011-09-27T19:39:53.147 回答