我有一个带有多种方法的 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
}
}
关于php - Controller 内的 Codeigniter 全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7151990/