Welcome Guest, Not a member yet? Register   Sign In
Retreiving Values from a Model
#1

[eluser]ufasoli[/eluser]
Hello all,
I've been trying to recover values from a model after beign initialised.

Here is how the application works

I've got a controller named "Account" which loads a view in which the user identifies himself. When he clicks on the Ok button a function "checkLogin" is called(by an Ajax call) to verify his credentials if the username and password are correct, the "init" function of the model is called and all the model variables are initialised with the user's information from the database. After this is done the user gets redirected to a new page(function "userAccount") where I would like to display all this information, that's why I pass "$this->user" as argument on the "$this->load->view('user', $this->user)", but all the variables are now empty...
So my question is: is it possible to keep the values of the model once they have been initialised? or do I have to call every time the 'init' method of the Model?? I have tried initialising the variables within the model's constructor, but the problem is still there.. I know as well that this could be done with session variables but I'd rather not do it that way.

here is my controller

Code:
<?php


class Account extends Controller
{
    function __construct()
    {
        
        parent::Controller();
        $this->load->helper('url');
        $this->load->database();
        $this->load->model('User', 'user', true);

    
    }

    function index()
    {    
        

        $this->load->view('logIn');

        
    }
    
    function checkLogin()
    {
        
        
        
        $login = $_POST['login'];
        $pwd = $_POST['pwd'];
        
        
              $query = $this->db->getwhere('utilisateurs', array('userid' => $login, 'pwd'=> $pwd));
        
        
        
        if($query->num_rows() != 1)
        {
                $msgLogin = "<h3 style=\"color: #663300;\"> Erreur de Connexion : </h3> <h4> Votre identifiant ou votre mot de passe est incorrect. </h4>";
    
            echo $msgLogin;

        }
        else
        {
            $query->free_result();
            $this->user->_init($_POST['login'], $_POST['pwd']);
            
    echo $this->ajax->tag("location.href ='".base_url()."Account/userAccount'");
            
                
            
        }
        
        
    }
    
    function userAccount()
    {
        $this->load->view('user', $this->user);
    }
    
        
}    
    
?&gt;
and here is my model

Code:
&lt;?php


class User extends Model
{

var $userid = "";
var $lastname = "";
var $name = "";


    
    function __construct()
    {
        parent::Model();
            
    
    }
    
    function _init($userid, $pwd)
    {
        
        $userInfo = $this->db->getwhere('utilisateurs', array('userid'=>$userid, 'pwd'=>$pwd));
        
        if($userInfo->num_rows() != 1)
        {
            return ;
        }
        else
        {
            foreach ($userInfo->result_array() as $row)
            {
                $this->userid = $row['userid'];
                $this->firstname = $row['firstname'];
                $this->lastname = $row['lastname'];
                
                
            }
            
            $userInfo->free_result();
        }
            
        
        
    }
    
    

    
}



?&gt;

Thanks in advance and sorry for my bad english

Ulises


Messages In This Thread
Retreiving Values from a Model - by El Forum - 11-19-2007, 07:32 AM
Retreiving Values from a Model - by El Forum - 11-19-2007, 07:39 AM
Retreiving Values from a Model - by El Forum - 11-19-2007, 07:58 AM
Retreiving Values from a Model - by El Forum - 11-20-2007, 01:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB