1

在我的应用程序中,我试图将用户信息保存在缓存变量中并以另一种方法访问它。我可以在相同的方法中访问它。但是当我尝试访问该方法时,它返回 null。我需要知道如何实现这一点,请有人帮我举个例子,因为我是这项技术的新手。

在方法内部:

Cache::set('user', $user);

用另一种方法访问它:

$user = Cache::get('user');

我想在访问它后清除它。

4

1 回答 1

0

而不是使用缓存来存储变量。

您可以在类中声明变量如下

class test{
    public $user = []; //declare your function here.

    function abc(){
        $this->user = $user; //Assign value to variable
    }

    function xyz(){
        $user = $this->user; 
        print_r($user);
    }

}
于 2020-03-18T06:01:09.610 回答