[英]Codeigniter global variable within controller
我有一个带有几种方法的控制器,它们都有相同的变量。 我正在寻找一种方法让他们共享相同的变量。 做这个的最好方式是什么?
我现在拥有的:
class Example extends CI_Controller{
public function test{
$variable = "awesome";
}
public function demo{
$variable = "awesome";
}
}
怎么样...
class Example extends CI_Controller
{
public $variable = "awesome";
public function test()
{
echo $this->variable; // awesome
}
public function demo()
{
echo $this->variable; // awesome
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.