I have checked codeigniter's documentations but there is no special page or information about it. All I wanna know is how it's working. I have this code and it's working!, What I'm wondering how is_unique working when there's no access to any model or database. Is there any class in codeigniter that is_unique uses it to retrieve data based on the information like the name of the table and the field you give it to? and that's the code:
Email input in the view:
echo form_input('email_address', set_value('email_address'), 'placeholder="Email"');
And the controller:
function create_member()
{
$this->load->library('form_validation');
// field name, error message, validation rules
$this->form_validation->set_rules('email_address', 'Email Address', 'trim|required|valid_email|is_unique[membership.email]');
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]');
$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]');
$this->form_validation->set_error_delimiters('<div class="alert alert-error"><a class="close" data-dismiss="alert">×</a><strong>', '</strong></div>');
if($this->form_validation->run() == FALSE)
{
$this->load->view('pages/signup_form');
}
else
{
$this->load->model('admin/Users_model');
if($query = $this->Users_model->create_member())
{
$this->load->view('pages/signup_successful');
}
else
{
$this->load->view('pages/signup_form');
}
}
}
and her's the model:
function create_member()
{
$new_member_insert_data = array(
'email' => $this->input->post('email_address'),
'user_name' => $this->input->post('username'),
'pass_word' => md5($this->input->post('password'))
);
$insert = $this->db->insert('membership', $new_member_insert_data);
return $insert;
}