Hej, nu har jeg siddet 1 time eller 2 og prøver at finde ud af hvordan jeg tjekker om brugeren allerede findes i databasen, håber en kan finde ud af hvad jeg gør forkert...
så har jeg lige et spørgsmål: i en model fi,l kan jeg så godt hente POST og GET osv. eller KUN i controlleren? for synes ikke jeg kan få det til at funke ordenligt.
her er min controller
- public function submit() {
-
- if ($this->_submit_validate() === FALSE) {
- $this->index();
- return;
- echo "FORKERT";
- }
-
- $this->load->model('member_model');
- $tjek_bruger = $this->member_model->username_check();
-
- if($tjek_bruger === TRUE)
- {
- $new_member_insert_data = array(
- 'fornavn' => $this->input->post('fornavn'),
- 'efternavn' => $this->input->post('efternavn'),
- 'email' => $this->input->post('email'),
- 'hood' => $this->input->post('hood'),
- 'city' => $this->input->post('city'),
- 'username' => $this->input->post('username'),
- 'password' => md5($this->input->post('password'))
- );
-
- $this->db->insert('users', $new_member_insert_data);
- //redirect($this->load->view('oprettet_view'));
- $data['content'] = 'oprettet_view';
- $this->load->view('includes/template', $data);
- }
-
- }
-
- private function _submit_validate() {
-
- // validation rules
- $this->form_validation->set_rules('fornavn', 'Fornavn',
- 'required|alpha_numeric|min_length[2]|max_length[30]');
-
- $this->form_validation->set_rules('efternavn', 'Efternavn',
- 'required|alpha_numeric|min_length[2]|max_length[70]');
-
- $this->form_validation->set_rules('hood', 'Hood',
- 'required|numeric|min_length[4]|max_length[4]');
-
- $this->form_validation->set_rules('city', 'City',
- 'required|min_length[4]|max_length[90]');
-
- $this->form_validation->set_rules('username', 'Username',
- 'required|alpha_numeric|min_length[6]|max_length[12]');
-
- $this->form_validation->set_rules('username', 'Username',
- 'required|alpha_numeric|min_length[6]|max_length[12]');
-
- $this->form_validation->set_rules('password', 'Password',
- 'required|min_length[6]|max_length[12]');
-
-
- $this->form_validation->set_rules('email', 'E-mail',
- 'required|valid_email');
-
- return $this->form_validation->run();
-
- }
Her er min model fil
- <?php
-
- class Member_model extends Model {
-
- function __construct()
- {
- parent::model();
- }
-
- function validate($username, $password)
- {
- $this->db->where('username', $username);
- $this->db->where('password', sha1($password));
- $query = $this->db->get('users');
-
- //Hvis den fandt noget i databasen return true
- if($query)
- {
- return true;
- } else {
- return false;
- }
- }
-
- function create_member($new_member_insert_data)
- {
- if($new_member_insert_data)
- {
- $this->input->xss_clean($new_member_insert_data);
- $insert = $this->db->insert('users', $new_member_insert_data);
- return $insert;
- } else {
- return false;
- }
- }
-
- function username_check()
- {
-
- $this->db->select('username');
- $this->db->where('username', $this->input->post('username'));
- $query = $this->db->get('users')->num_rows();
-
- if ($query > 0)
- {
- $this->form_validation->set_message('username_check', 'Brugernavnet er allerede taget');
- return FALSE;
- }
- else
- {
- return TRUE;
- }
- }
-
- }
tusind tak forhånd