是否有可能如何顯示控制器字符串以在codeigniter中查看? 即時進行表單驗證,以檢查數據庫中是否存在某個記錄。如何在codeigniter中使用FormValidation
這裏是我的控制器
function create_customer()
{
// field name, error message, validation rules
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]|callback_username_exists');
$this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
$this->form_validation->set_rules('password2', 'Password Confirmation', 'trim|required|matches[password]');
if($this->form_validation->run() == FALSE)
{
$this->load->view('admin/users/admin_form');
}
else
{
if($query = $this->usermodel->create_customer())
{
redirect('userslist');
}
else
{
$this->load->view('admin/users/admin_form.php');
}
}
}
function username_exists($key)
{
$this->usermodel->username_exists($this->input->post('username'));
}
代碼在這裏對我的模型
function create_customer()
{
$new_member_insert_data = array(
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'password ' => md5($this->input->post('password '))
);
$insert = $this->db->insert('users', $new_member_insert_data);
return $insert;
}
function username_exists($key)
{
$this->db->where('username',$this->input->post('username'));
$query = $this->db->get('users');
if ($query->num_rows() > 0){
return true;
}
else{
return false;
}
}
什麼,我想發生是代碼;我將如何顯示預期的錯誤消息,如「用戶名已存在」,我想在我的視圖中顯示它。這可能嗎?或者我應該嘗試採取另一種方法?
你能解釋一下這裏有什麼問題嗎? – Tapos 2011-05-23 18:06:32