2017-07-14 107 views
1

我正在使用codeigniter插入數據。 這是我得到的後期數據數組。如何驗證codeigniter中的數組值

問題:我送了app_soft_idslang_idsworking_days形成我的HTML表單,所以我拿到後中所示排列後這裏。但是codeigniter未驗證這三個值。

我如何驗證這三個值? codeigniter驗證後顯示此錯誤。我沒有得到,我怎麼可能正確地發送數據,但CI驗證仍然沒有得到它。

應用程序ID字段是必需的。

Langusge IDs字段是必需的。

需要工作日字段。

這是我的文章數組。

Array 
(
    [app_soft_ids] => Array 
     (
      [0] => 66 
      [1] => 68 
     ) 

    [lang_ids] => Array 
     (
      [0] => 4 
      [1] => 5 
     ) 
    [working_days] => Array 
     (
      [0] => 4 
     ) 

    [shift] => Y  
    [status] => O 
    [expiry_date] => 10/07/2017 
) 

這是我的驗證代碼:

$config = array(
    'app_validation' => array(
     array(
       'field' => 'app_soft_ids', 
       'label' => 'Application IDs', 
       'rules' => 'required|numeric' 
     ), 
     array(
       'field' => 'lang_ids', 
       'label' => 'Langusge IDs', 
       'rules' => 'required|numeric' 
     ), 
     array(
       'field' => 'working_days', 
       'label' => 'Working Days', 
       'rules' => 'required|numeric' 
     ), 
     array(
       'field' => 'shift', 
       'label' => 'Shift', 
       'rules' => 'required|trim|max_length[1]|' 
     ) 
    ) 
); 
+2

您正在驗證數組數據類型的數值規則。檢查此鏈接https://github.com/bcit-ci/CodeIgniter/pull/2547 –

+2

檢查此答案https://stackoverflow.com/questions/17771980/how-to-validate-array-value-in-codeigniter –

回答

0

感謝kumar_v評論我已經得到驗證陣列只需添加[]初始化的方式。

$config = array(
    'app_validation' => array(
     array(
       'field' => 'app_soft_ids[]', 
       'label' => 'Application IDs', 
       'rules' => 'required|numeric' 
     ), 
     array(
       'field' => 'lang_ids[]', 
       'label' => 'Langusge IDs', 
       'rules' => 'required|numeric' 
     ), 
     array(
       'field' => 'working_days[]', 
       'label' => 'Working Days', 
       'rules' => 'required|numeric' 
     ), 
     array(
       'field' => 'shift', 
       'label' => 'Shift', 
       'rules' => 'required|trim|max_length[1]|' 
     ) 
    ) 
);