Welcome Guest, Not a member yet? Register   Sign In
How do you pass a model variable to a controller
#1

[eluser]Kraig[/eluser]
Below is my model. How can I get the $num_rows variable if I'm in a controller? I know I could get a function like this
Code:
$this->Upload_model->category();
but how would I access $num_rows if I wanted to create a public variable?

Code:
class Upload_model extends CI_Model {

public $num_rows;

public function category()
{  
  $query = $this->db->query('SELECT * FROM category ORDER BY name');
  $num_rows = $query->num_rows();
  $val = $query->result_array();

  if($num_rows > 0)
  {
      return $val;
  }
  else
  {
   return;
  }
  
}

}
#2

[eluser]alexwenzel[/eluser]
Code:
$this->Upload_model->num_rows

i guess
#3

[eluser]Kraig[/eluser]
Wow idiot....just saw that I didn't use $this->num_rows; so I should be able to access it as $this->Upload_model->num_rows;

Right??
#4

[eluser]alexwenzel[/eluser]
[quote author="Kraig" date="1345414887"]Wow idiot....just saw that I didn't use $this->num_rows; so I should be able to access it as $this->Upload_model->num_rows;

Right??[/quote]

ofc you need to set a class proeprty with $this. didnt even expected that xD
#5

[eluser]CroNiX[/eluser]
Code:
$data['num_rows'] = $query->num_rows();
$data['val'] = $query->result_array();

return $data;

or, you could always just count($val) in your controller using your existing code.




Theme © iAndrew 2016 - Forum software by © MyBB