Welcome Guest, Not a member yet? Register   Sign In
login system, how to go from controller to view to model
#1

[eluser]jvittetoe[/eluser]
i am trying to figure out the basic pipeline for a simple login process. users come to the home page, which loads the home controller and home view. the home view contains a simple form for logging in. when they submit, i load the login controller which loads the login model which queries the useraccounts table in my database. if the user exists the login model will load the users dashboard view, if the user doesnt exist or bad info, the login model will load the home view again. is this the proper pipeline? let me post my files.

home view
Code:
<h2>Login In</h2>
    <p>Fill out the form below to login to your account!</p>
    &lt;?php echo form_open('login');?&gt;
    
        <label for="username">Username</label><br />
        &lt;input  type="text" name="username" id="username" /&gt;<br />
        <label for="password">Password</label><br />
        &lt;input  type="password" name="password" id="password" /&gt;<br />
        &lt;input type="submit" value="Login" /&gt;
        
    &lt;/form&gt;

login controller
Code:
&lt;?php

    class Login extends Controller{
    
        function Login(){
        
            parent::Controller();
            $this->load->helper( array('url', 'form') );
        }
        
        function index(){
        
            $this->load->model('Login_model','', TRUE);
            $this->load->view('dashboard'); //send user to their dashboard
        }
    
    }

?&gt;

login model
Code:
&lt;?php

class Login_model extends Model{

    
    function Login_model(){
        
        parent::Model();
    }
    
    function login($username = '', $password = ''){
    
        if($user){
            $sql = $this->db->query("SELECT * FROM useraccounts WHERE usernamr = $username and password = md5($password)");
            if($sql->num_rows() > 0){
                return true;
            }
        } else {
            return false;
        }
    
    
    
        /*
        
        var $username = $_POST['username'];
        var $password = $_POST['password'];
    
        $sql = "SELECT uuid ";
        $sql .= "FROM useraccounts ";
        $sql .= "WHERE username='$username' AND password=MD5('$password') ";
        
        $result = mysql_query($sql);
        $row = mysql_fetch_assoc($result);
        $uuid = $row['uuid'];
        
        if($uuid > 0) {
            
            session_start();
            
            $_SESSION['logged_in'] = TRUE;
            
            $data['title'] = "Welcome to MyFi ~ A Personal Finance Web Application // My Home";
            $this->load->view('userHome', $data);
            echo 'workeded';
            echo $uuid;
            echo $username;
            echo $password;
        }
        else {
            $this->load->view('login_v', $data);
            echo 'brokeded';
            echo $uuid;
            echo $username;
            echo $password;
        }
        
        */
    }
    
}

?&gt;

these files are still pretty bare, i just want to amke sure im headed in the right direction and i have the basic concepts down. thanks.


Messages In This Thread
login system, how to go from controller to view to model - by El Forum - 06-24-2007, 11:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB