开发者

to pass value of a variable in one function to another using session

开发者 https://www.devze.com 2023-03-12 09:40 出处:网络
I have a class Blocka_Model (actually a MODEL in KOhana framework) with 2 functions input() and output().The function input is called from a function wriiten inside a controller called Home_Controller

I have a class Blocka_Model (actually a MODEL in KOhana framework) with 2 functions input() and output().The function input is called from a function wriiten inside a controller called Home_Controller and it passes an argument to the function input. Now I want that argument passed to input() function to be accessible in the function output(). Both the functions input() and output() are inside Model class Blocka_Model. I want to get that argument $val from input() to output)

class Blocka_Model extends Block_Model {

    protected $tablname = 'moves';

    public 开发者_StackOverflow中文版function input($val) {  ...  } 

    public function output() {  ...  }

}


Since your title says you wish to use a session:

class Blocka_Model extends Block_Model {

    protected $session_unique_id;

    public function __construct() {
         $this->session_unique_id = uniqid();
    }

    /*
     * Save $val in our current session
     */
    public function input($val) {
        $_SESSION[get_class($this).$this->session_unique_id] = $val;
    } 

    /*
     * Check for a value in our session
     *  - if it is set, return it
     *  - else return null
     */
    public function output() {   
        return isset($_SESSION[get_class($this).$this->session_unique_id]) ? 
                     $_SESSION[get_class($this).$this->session_unique_id] : null;
    }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消