Welcome Guest, Not a member yet? Register   Sign In
Passing Values from one function to another within the controller
#1

[eluser]makkal[/eluser]
Hi,

I have searched the forum for a while, but i didn't get the exact information for my question.

Question:
I need to pass the values from one function to another within the controller.

Here's the example

Code:
class MyClass extends Controller{
  public $myVariable;

  function MyClass() {
    parent::Controller();
  }

  function myFunction1() {
    $this->myVariable = $_POST['name'];
  }

  function myFunction2() {
    echo $this->myVariable;
  }

}

But i couldn't receive the value in myFunction2() that was stored in myFunction1().
Looking for the best solution. Thank you.

-Mak
#2

[eluser]Kindari[/eluser]
Look into using session variables.
#3

[eluser]WanWizard[/eluser]
That only works if myFunction1 somehow calls myFunction2.

If you are talking about multiple page requests, remember that the web is stateless, myFunction2 doesn't know there was a previous request to that same controller and myFunction1 was executed. Sessions are indeed the preferred option to pass data from one request to the next.

Maybe it's not a bad idea to read up on the basics of PHP and web development, it will save you a lot of frustration...
#4

[eluser]makkal[/eluser]
Yes, i am looking for the values in multiple page requests. That's my wild desire to pass the values among the functions in a controller.

Just asked here hoping to find any solution. It seems a impossible one.

-Mak
#5

[eluser]LuckyFella73[/eluser]
Quote:Just asked here hoping to find any solution. It seems a impossible one.

It's not the time to give up now - I'm sure there is a solution, it's just
that it don't work the way you tried to do it. Using sessions like Kindari
suggested could be a way to achieve what you wanted to.
#6

[eluser]makkal[/eluser]
Yes LuckyFella, i will follow the way of using session variables.

Thank you all.
Mak




Theme © iAndrew 2016 - Forum software by © MyBB