Fat models and thin controllers in Codeigniter
14:22 22 Feb 2015

This is a user.php controller:

public function verifyLogin() {
    if (isset($_POST["email"])) {
        $e = $this->input->post("email");
        $p = $this->input->post("pass");

        $this->form_validation->set_rules("email", "email", "required|valid_email|xss_clean");
        $this->form_validation->set_rules("pass", "password", "required|xss_clean");

        if ($this->form_validation->run()) {
            $data = array(
                'select' => '*',
                'table' => 'users',
                'where' => "email = '$e' AND activated = '1'"
            );

            $checklogin = $this->query2->selectData($data);

            if ($checklogin === FALSE) {
                echo "querying userInfo fails. email is wrong or activation not done";
                exit();
            } else {
                foreach ($checklogin as $row) {
                    $dbid = $row->id;
                    $dbusername = $row->username;
                    $dbpassword = $row->password;
                    $dbemail = $row->email;
                    if ($p === $dbpassword) {
                        $login_data = array(
                            'name' => $dbusername,
                            'email' => $dbemail,
                            'password' => $dbpassword,
                            'id' => $dbid,
                            'expire' => '86500',
                            'secure' => TRUE,
                            'logged_in' => TRUE
                        );
                        $this->input->set_cookie($login_data);
                        $this->session->set_userdata($login_data);
                        if ($this->session->userdata("logged_in")) {
                            $time = time();
                            $now = unix_to_human($time, TRUE, 'us');
                            $updateLogin = $this->query1->updateLogin($e, $now);
                            if ($updateLogin) {
                                echo "success";
                            } else {
                                echo 'update failed';
                            }
                        } else {
                            echo "session failed";
                        }
                    }else{
                        echo 'password incorrect';
                    }
                }
            }
        } else {
            echo "form validation fails";
        }
    } else {
        $this->load->view('header');
        $this->load->view('login');
        $this->load->view('modal');
        $this->load->view('footer');
    }
}

this is model.php

public function selectData($data){
    
    if(isset($data['direction'])){
        $dir = $data['direction'];
    }else{
        $dir = "ASC";
    }
    
    if(isset($data['offset'])){
        $off = $data['offset'];
    }else{
        $off = '0';
    }
    
    if(isset($data['select']) && isset($data['table'])){
        $this->db->select($data['select'])->from($data['table']);
    }
    
    if(isset($data['where'])){
        $this->db->where($data['where']);
    }
    if(isset($data['order_by_name'])){
        $this->db->order_by($data['order_by_name'], $dir);
    }
    if(isset($data['limit'])){
        $this->db->limit($data['limit'], $off);
    }
    
    $query = $this->db->get();
    
    if($query){
        $d = $query->result();
        return $d;
    }else{
        return FALSE;
    }
    
}

Is this a good way of querying the database?

I am new to MVC and I am reading everywhere about "fat models and thin controllers", what can be done to make it a good MVC architecture?

mysql codeigniter model-view-controller