Welcome Guest, Not a member yet? Register   Sign In
model row data to controller
#1

[eluser]CI2RULZ[/eluser]
I want to pass a single row of data from the model to the controller, so that the controller can be used to redirect based on that data.

For example, if account status = 0, do this, or = 1, do this.

I can get this to work fine by leaving all the logic in the model and only calling the model function in the controller, but shouldnt the controller be directing the traffic? I just can't figure out how I can use the data from the model in the controller for the if else statements.
#2

[eluser]osci[/eluser]
Two options come in my mind.
If you just need an answer to your controller for status write in your model a function to return true or false depending on the model's answer do your if
i.e.
Code:
//model
function check_status($id)
{
   $query = $this->db->from('your_table')->select('status')->where('id',$id)->get()->row;

   if($query->num_rows() > 0)
   {
      return ($row->status == 1)?TRUE:FALSE;
   }
   return FALSE;
}

//controller

if ($this->your_model->check_status($id))
{
   //
} else {
   //
}


If you want to use more data from that row then you would do
Code:
//model
function get_data($id)
{
   $query = $this->db->from('your_table')->where('id', $id)->get();
   return $query;
}
//controller

$row = $this->your_model->get_data($id)->row();
if ($row->status==1)
{
   //
} else {
   //
}




Theme © iAndrew 2016 - Forum software by © MyBB