Reputation: 739
How can definition a global variable for use in all function controller
class TestController extends Controller
{
private $x;
public function index()
{
$this->$x ='22';
}
public function send_message()
{
echo $this->$x;
}
}
Upvotes: 6
Views: 67167
Reputation: 1
If you want to make global variable in controller, the following code will work definitely:
private $x = 22;
public function index()
{
print_r($this->x);
die();
}
Upvotes: 0
Reputation: 1824
Write $this->x
rather than $this->$x
class TestController extends Controller
{
private $x;
public function index()
{
$this->x ='22';
}
public function send_message()
{
echo $this->x;
}
}
Upvotes: 42