2012-11-19 42 views
0

我試圖使用笨表單驗證庫顯示在同一時間在兩個不同語言的兩個不同行,但它拋出一個錯誤:如何同時使用兩種不同語言的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 

回答

2

core/libraries/form_validation.php中525行的sprintf()函數只有兩個參數。

$message = sprintf($line, $this->_translate_fieldname($row['label'])); 

第一個參數必須是帶指定插入點的字符串。以下參數(在sprintf函數中)必須與插入點的數量相匹配。而codeigniter只使用一個。

從笨Userguide: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

+0

我用你的建議,但錯誤仍然是same.A PHP錯誤遇到 嚴重性:警告 消息:的sprintf():參數太少 文件名:庫/ Form_validation.php 行號碼:525 – motto

+0

Aha%2 $ s無法正常工作,但%1 $ s工作正常!你是怎麼想出來的?那背後的邏輯是什麼?我很好奇 – motto

+1

格言:我已經編輯了一個鏈接到PHP手冊的答案。這些例子很好地解釋了它。 – nielsiano

相關問題