控制器中的全局变量 laravel 5.3
global variable in controller laravel 5.3
如何定义一个全局变量用于所有功能控制器
class TestController extends Controller
{
private $x;
public function index()
{
$this->$x ='22';
}
public function send_message()
{
echo $this->$x;
}
}
写$this->x
而不是$this->$x
class TestController extends Controller
{
private $x;
public function index()
{
$this->x ='22';
}
public function send_message()
{
echo $this->x;
}
}
如果你想在controller中创建全局变量,下面的代码肯定可以:
private $x = 22;
public function index()
{
print_r($this->x);
die();
}
如何定义一个全局变量用于所有功能控制器
class TestController extends Controller
{
private $x;
public function index()
{
$this->$x ='22';
}
public function send_message()
{
echo $this->$x;
}
}
写$this->x
而不是$this->$x
class TestController extends Controller
{
private $x;
public function index()
{
$this->x ='22';
}
public function send_message()
{
echo $this->x;
}
}
如果你想在controller中创建全局变量,下面的代码肯定可以:
private $x = 22;
public function index()
{
print_r($this->x);
die();
}