我正在尝试使用codeigniter表单验证库同时显示两种不同语言的两个不同的行,但它会引发错误:
$this -> form_validation -> set_message('required', 'Warning %s should not be empty! <br /> Dikkat %s alanı boş bırakılmamalıdır.');
有没有办法像这样使用这个功能而不会遇到这个错误:
A PHP Error was encountered
Severity: Warning
Message: sprintf(): Too few arguments
Filename: libraries/Form_validation.php
Line Number: 525
答案 0 :(得分:2)
core / libraries / form_validation.php中第525行的sprintf()函数只有两个参数。
$message = sprintf($line, $this->_translate_fieldname($row['label']));
第一个参数必须是带有指定插入点的字符串。以下参数(在sprintf函数中)必须与插入点的数量匹配。 codeigniter只使用一个。
来自Codeigniter用户指南:http://ellislab.com/codeigniter/user_guide/libraries/form_validation.html
If you include %s in your error string, it will be replaced with the "human" name you used for your field when you set your rules.
但是,问题的解决方案是:
$this->form_validation->set_message('required', 'Warning %1$s should not be empty! <br /> Dikkat %1$s alanı boş bırakılmamalıdır.');
%1 $ s表示sprintf()中字符串参数之后的第一个参数。这里的例子很好地解释了它:http://dk1.php.net/sprintf