【发布时间】:2016-06-22 10:42:22
【问题描述】:
我在控制器内定义了全局变量,但我在 index() 函数内赋值。值可以在 index() 内部访问,但不能在 about 和其他函数内部访问。我该怎么做 ??
class Manage_business extends CI_Controller
{
var $id;
public function __construct()
{
parent::__construct();
}
public function index($no)
{
$this->id=$no;
echo $this->id;
}
public function about()
{
echo $this->id;
die();
}
}
【问题讨论】:
-
构造函数内部有赋值。我在 index() 内部分配。即使我不想要超级全局变量。
-
如果您直接使用 about 函数,那么您无法通过 index 函数设置 $this->id 的值,因为它从未被调用过。
-
拳头我的索引函数调用。之后其他人。
-
你可以像
$this->about($no)在索引函数中调用一样传递它
标签: php codeigniter