CodeIgniter Forums

Full Version: Pass data between functions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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.

El Forum

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

El Forum

[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.

El Forum

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

El Forum

[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;
  }

El Forum

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