I have a question relating to properties for a specific instance of a CI model. For example:
There is a model called project_model. In the model it has a method calle Get_Projects:
$total_projects = $this->project_model->Get_Projects($options);
When this is called it creates a property in the model like so:
$query = $this->db->get('projects');//query
$this->num_rows = $query->num_rows();
return $query->result();
So after the method has been called and in the controller, I need to access num_rows:
$num_rows = $total_projects->num_rows;
(I know some of you may question the reason behind using num rows in the controller. It’s to do with setting the pagination. There may be better ways of doing it but there is no time in this particular project.)
My problem is that this creates a syntax error:
Severity: Notice
Message: Trying to get property of non-object
Filename: controllers/projects.php
Line Number: 110 ($num_rows = $total_projects->num_rows;)
Firstly why is this? I was thinking of using this: $this->project_model::num_rows instead? But then the num_rows won’t be specific to the $total_rows object will it? So it will just be for the entire model.
BTW: I read the CI guide on models but there wasn’t any information on creating instances of models at all.
EDITED: I need the result of num_rows property to be object-specific. So for example:
$a=$this->project_model->Get_Projects($options);
$b=$this->project_model->Get_Projects($options);
$num_rows = $this->project_model->num_rows;
The final line will get the result of $b num_rows and not $a. So How do I call it so that I can make it object-specific? (Obviously I could store it before the second call in a variable.)
You could just instantiate a the model each time you need it.
This way you can get/set any attributes of each model instance seperatly.