-3

I have controller that has functions and I want to use one variable through them

class TrainerController extends \BaseController {
  public function one(){
    $variable = "some data";
  }

  public function two()
  {
    //How to use $variable here ?!
  }
}

I tried to use session but session scope in one function (view) only thanks in advance

Mohamed Gamal
  • 145
  • 1
  • 2
  • 12

1 Answers1

2

Make it a property

class TrainerController extends \BaseController 
{

  private $variable;

  public functionOne(){
    $this->variable = "some data";
  }

  public functionTwo()
  {
    echo $this->variable; //outputs 'some data' IF this 1st method has already been called
  }
}
Steve
  • 20,703
  • 5
  • 41
  • 67