$sort_order=$this->input->post('sort_order','Sort Of Category','trim|required|max_length[128]|xss_clean|is_unique[categories.sort_order]');
为什么is_unique
功能在这里不起作用?
答案 0 :(得分:0)
应该是对控制器
上的表单验证的set_ruleshttps://www.codeigniter.com/user_guide/libraries/form_validation.html
$this->form_validation->set_rules('sort_order','Sort Of Category','trim|required|max_length[128]|xss_clean|is_unique[categories.sort_order]');
https://www.codeigniter.com/user_guide/libraries/form_validation.html#setting-validation-rules
https://www.codeigniter.com/user_guide/libraries/form_validation.html#rule-reference
<?php
class Example extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->library('form_validation');
}
public function index() {
$data['title'] = 'Example';
$this->form_validation->set_rules('sort_order','Sort Of Category','trim|required|max_length[128]|is_unique[categories.sort_order]');
if ($this->form_validation->run() == false) {
$this->load->view('header', $data);
$this->load->view('example', $data);
$this->load->view('footer');
} else {
// You can put your update or insert model function here
redirect('success_controller');
}
}
}
答案 1 :(得分:0)
$c_name=$this->input->post('c_name');
$sort_order=$this->input->post('sort_order');
$this->load->library('form_validation');
$this->form_validation->set_rules('c_name','Category Name','trim|required|max_length[128]|xss_clean');
$this->form_validation->set_rules('s_order','Sort Order','Sort Of Category','trim|required|xss_clean|is_unique[categories.sort_order]');