Welcome Guest, Not a member yet? Register   Sign In
Quick example of passing data between model and controller...
#1

[eluser]nikefido[/eluser]
For instance, if I make a model and it returns an array of data, how do I pass that array of data back into the controller so I can output it to a view?

Thanks! (im pressed for time on a project, and code igniter is going to save my life!)
#2

[eluser]nikefido[/eluser]
for now I'm going to assume I can do

Code:
$myData = $this->load->model('my_model');

And make sure my model returns a value.
#3

[eluser]MadZad[/eluser]
A model isn't necessarily a one-trick pony - it can have many methods (functions). So, instead of the code you listed, your controller would first load the model (often in the constructor):
Code:
$this->load->model('My_model');
then call a function in the model when needed:
Code:
$myData = $this->My_model->gimme_some_data();

Therefore, your model would need that function:
Code:
class My_model extends Model {
  
  function My_model() {
    parent::Model();
  }

  function gimme_some_data () {
    // assemble data in the $results array
    return $results;
  }
}
#4

[eluser]nikefido[/eluser]
Yes, I am using my model like that - i was dumbing it down for the example.

Thanks for the input tho - you gave me a good idea for the project (too complex to explain atm).

~Fido




Theme © iAndrew 2016 - Forum software by © MyBB