CodeIgniter Forums
Best way to pass a couple of variables from a Controller to a Model? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Best way to pass a couple of variables from a Controller to a Model? (/showthread.php?tid=43293)



Best way to pass a couple of variables from a Controller to a Model? - El Forum - 07-06-2011

[eluser]brucebat[/eluser]
I have some variables :

$completedstaffrows and $completedeventrows that I need to control a for loop.

I was thinking about creating a class with just attributes and passing it to the model, but how does one pass it. I tried passing it through the function call from my controller and in the load model function but not luck.

I guess I could use a session but Is that really the best way?

Thanks


Best way to pass a couple of variables from a Controller to a Model? - El Forum - 07-06-2011

[eluser]ccschmitz[/eluser]
Is there a reason you don't want to pass them as parameters to your model methods? i.e. do something like this in your controller:

Code:
$this->load->model('staff_model');
$this->staff_model->update_staff_events($completedstaffrows, $completedeventrows);

Then just have your model accept these params:

Code:
function update_staff_events($completedstaffrows, $completedeventrows)
{
    // do stuff with your vars...
}



Best way to pass a couple of variables from a Controller to a Model? - El Forum - 07-06-2011

[eluser]toopay[/eluser]
Unless you process that variable in different http request, you doesn't need to use session.