CodeIgniter Forums
Pass data between functions - 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: Pass data between functions (/showthread.php?tid=2352)



Pass data between functions - El Forum - 07-31-2007

[eluser]Stuart Marsh[/eluser]
Can anybody tell me how I can pass data between controllers quickly and efficiently?
I have two controllers. Controller A displays a form and validates the data. I want controller A to redirect the page and pass the form data to controller B.
I dont really want to pass the data through the URI, but will if there is no other way.
Anybody got any suggestions?

Cheers.


Pass data between functions - El Forum - 07-31-2007

[eluser]sophistry[/eluser]
store in db or session.


Pass data between functions - El Forum - 07-31-2007

[eluser]Michael Wales[/eluser]
Why would you want to transfer data from Controller to Controller - the point of the Controller is so all of your work with a particular set of data is stored within one location.

For example, a controller named users. It would have everything to do with users: register, login, logout, profiles - that is it's purpose.

Regardless, if you really wanted to do it (and break the MVC model) - store it in a DB or session.


Pass data between functions - El Forum - 07-31-2007

[eluser]Stuart Marsh[/eluser]
Thanks for the suggestions.
Walesmd - Gettin myself confused.
I want to pass values between functions not controllers.


Pass data between functions - El Forum - 07-31-2007

[eluser]Michael Wales[/eluser]
Oh that's easy then - to call a function from another function just call it as such:

Code:
function get_name() {
  $a = 'bob';
  $str = $this->say_hi($a);
  return $str;
  }

  function say_hi($name) {
    return 'Hello, ' . $name;
  }



Pass data between functions - El Forum - 08-01-2007

[eluser]Stuart Marsh[/eluser]
Cool.
Cheers mate.