Welcome Guest, Not a member yet? Register   Sign In
Login2
#2

[eluser]Tpojka[/eluser]
You didn't pass the data. Right way is view->controller->model.
You passed data from view with function
Code:
form_open('admin/clogin/process');
, but in controller you have to use same data too for passing it to model.
So it should be something like:
Code:
public function process(){
        
        $username = $this->input->post('username', TRUE);  
        $password = $this->input->post('password', TRUE);

        // Load the model
        $this->load->model('Login_model');
        // Validate the user can login
        $result = $this->Login_model->validate($username, $password); // here you send data to model
        // Now we verify the result
        if(! $result){
            // If user did not validate, then show them login page again
            $this->index();
        }else{
            // If user did validate,
            // Send them to members area
            redirect('admin/admin');
        }        
}
, and in model you have to adopt those data in form of method arguments:
Code:
public function validate($username, $password){ // same data you have sent from controller
  
        // Prep the query
        $this->db->get_where('username', $username);
        $this->db->get_where('password', $password);
        
        // Run the query
        $query = $this->db->get('username');
        // Let's check if there are any results
        if($query->num_rows() == 1)
        {
            // If there is a user, then create session data
            $row = $query->row();
            $data = array(
                    'username' => $row->username,
     'password' => $row->password,
                    'validated' => true
                    );
            $this->session->set_userdata($data);
            return true;
        }
        // If the previous process did not validate
        // then return false.
        return false;
    }
}

This should be the basic MVC principle and how is used in CI.

Check what have I changed and test it as well. I didn't read rest of the code.


Messages In This Thread
Login2 - by El Forum - 10-27-2013, 07:38 PM
Login2 - by El Forum - 10-27-2013, 11:49 PM
Login2 - by El Forum - 10-28-2013, 01:18 AM
Login2 - by El Forum - 10-28-2013, 01:23 AM
Login2 - by El Forum - 10-28-2013, 02:16 AM
Login2 - by El Forum - 10-28-2013, 02:21 AM
Login2 - by El Forum - 10-28-2013, 02:28 AM
Login2 - by El Forum - 10-28-2013, 02:42 AM
Login2 - by El Forum - 10-28-2013, 11:39 PM
Login2 - by El Forum - 10-29-2013, 02:37 AM
Login2 - by El Forum - 10-30-2013, 06:42 AM
Login2 - by El Forum - 10-30-2013, 06:50 AM
Login2 - by El Forum - 10-30-2013, 07:05 AM
Login2 - by El Forum - 10-30-2013, 06:55 PM
Login2 - by El Forum - 10-30-2013, 09:03 PM



Theme © iAndrew 2016 - Forum software by © MyBB