Search code examples
variablescontrollerkohanaglobalshared

Kohana Controller actions share variable


I want write one variable to access any action into same controller. I write one shared or global variable.

I using, Kohana 3.1.

It's possible !? I don't find any example or people with same question.


Solution

  • How about using a class property?

    <?php defined('SYSPATH') or die('No direct script access.'); 
    
    class Controller_Application extends Controller_Base {
          public $variable = FALSE;
    
          /* This will echo true */
          public function action_index()
          {
                $this->variable = TRUE;
                echo Debug::vars($this->variable);
          }
    
          /* This will echo false */
          public function action_variable()
          {
                echo Debug::vars($this->variable);
          }
    }