Welcome Guest, Not a member yet? Register   Sign In
how to pass row( ) data from a model class function to a controller
#1

[eluser]Rob J Shillito[/eluser]
Hi,

I have literally started using codeigniter and am still getting my head around how it works. I am creating a simple login for a web app, but not sure how, after I have created a query in a model class, I can get the data back to the controller so I can apply some logic to it.

here's my code in my Controller index function:

Code:
function index()
{
  $data['title'] = "Login Page";
  $data['login'] = "Please Login";
  
  
  $this->load->helper('form');//loads the form helper
  if( $this->input->post("submit") ) {
  
    $this->load->model('loginscript', '',TRUE);//true loads the db
    $this->loginscript->checklogin($_POST['username'], $_POST['password']);
    
     $fullname = $this->loginscript->checklogin->fullname;//doesn't work
    
     if($fullname){
      echo "win";
     }
     else echo "fail";
    
     //****if the output is fine then redirect
     $this->load->helper('url');
     //redirect('/dashboard', 'location', 301);
  }//end of isset
  
  else
  {
   $this->load->view('loginpage', $data);//the pages in the view directory
  }
  
  
}

The code at the moment, for testing purposes, is trying to get the fullname value, which is stored in the db.

Here's the model code:

Code:
function checklogin($username, $password){
  
  $data['query'] = $this->db->get('profiles');
  
  //hashes and salts the password to check against the db entry
  $salt = "test";
  $password = md5($salt.$password);
  
  
  $this -> db -> select('username, password, fullname');
  $this -> db -> from('profiles');
  $this -> db -> where('username', $username);//checks username
  $this -> db -> where('password', $password);//checks password
  $this -> db -> limit(1);
  
  $login = $this->db->get();

  
  if($login->num_rows() == 1)
  {
  
    return $login->row();
   echo $rows->fullname;//works
  }
  else
  {
   return false;
  }  
}//end of checklogin function

Could someone enlighten me how you can output each field from the database separately in the Controller class?

Very much appreciated Smile

Many thanks

Rob Shillito


Messages In This Thread
how to pass row( ) data from a model class function to a controller - by El Forum - 11-17-2012, 03:12 AM



Theme © iAndrew 2016 - Forum software by © MyBB