1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

$this->load->library('form_validation');

$data = [
'_id' => $this->input->get("_id"),
'name' => $this->input->get("name"),
'covers' => $this->input->get("covers"),
];
// 将要验证的参数 set 进去
$this->form_validation->set_data($data);

// validate
$config = [[
'field' => '_id',
'rules' => 'required'
], [
'field' => 'name',
'rules' => 'required'
], [
// 数组需要在后面或两边加括号:covers[] 或 [covers]
'field' => 'covers[]',
'label' => 'cover',
'rules' => 'required'
]];

$this->form_validation->set_rules($config);
if ($this->form_validation->run() === false) {
return $this->form_validation->error_array();
}

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注