function create() { // Loader $this->load->helper('form'); #--- # Header $header = array( 'title' => 'Create user', 'description' => 'bla bla' ); $this->load->view('header.html', $header); # Body $this->load->view('user/create.html'); # Footer $this->load->view('footer.html'); if ($this->input->post('username') !== FALSE): # $u = new User(); $u->username = $this->input->post('username'); $u->name = $this->input->post('name'); $u->lastname = $this->input->post('lastname'); $u->email = $this->input->post('emnail'); $u->password = $this->input->post('password'); $u->password2 = $this->input->post('password2'); $u->user_type = $this->input->post('user_type'); if ($u->save()) { echo 'user registered'; } else { echo '<h3>Error...</h3>'; echo '<p>' . $user->error_string . '</p>'; } endif; }
class User extends DataMapper { var $validate = array( 'username' => array( 'label' => 'Nick', 'rules' => array('required', 'trim', 'unique', 'alpha_dash', 'min_length' => 3, 'max_length' => 20) ), 'name' => array( 'label' => 'Name', 'rules' => array('required', 'trim') ), 'lastname' => array( 'label' => 'Lastname', 'rules' => array('required', 'trim') ), 'email' => array( 'label' => 'E-mail', 'rules' => array('required', 'trim', 'valid_mail') ), 'password' => array( 'label' => 'Password', 'rules' => array('required', 'md5') ), 'password2' => array( 'label' => 'Password confirmation', 'rules' => array('required', 'matches' => 'password') ), 'user_type' => array( 'label' => 'User or admin?', 'rules' => array('required') ) ); }