【问题标题】:Kohana Controller actions share variable [closed]Kohana 控制器操作共享变量
【发布时间】:2013-04-04 04:54:19
【问题描述】:

我想写一个变量来访问同一个控制器的任何动作。我写了一个共享或全局变量。

我使用的是 Kohana 3.1。

有可能!?我没有找到任何例子或有相同问题的人。

【问题讨论】:

    标签: variables controller kohana global shared


    【解决方案1】:

    使用类属性怎么样?

    <?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);
          }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-10
      • 2016-09-02
      • 1970-01-01
      • 2014-06-29
      • 2013-05-06
      • 2019-10-02
      • 1970-01-01
      相关资源
      最近更新 更多