将新值重新分配给全局变量Laravel PHP [英] Reassign with new value to global variable Laravel PHP
本文介绍了将新值重新分配给全局变量Laravel PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Laravel项目中有以下代码段,其中我试图在方法ValidateValue()
中将值重新分配给全局变量$ischecked
和$isselectedValue
,并且尝试访问相同的代码具有第二个方法useThoseValues()
中更新后的值的变量,但我无法获取更新后的值.请帮助我
I have a below kind of snippet in my Laravel project where I'm trying to re-assign value to the global variable $ischecked
and $isselectedValue
in a method ValidateValue()
and I'm trying to access the same variable with the updated values in second method called useThoseValues()
but I couldn't get the updated value. Kindly help me on this
class testController extends controller {
public $isChecked = false;
public $isSelectedValue = 0;
public function ValidateValue(Request $req)
{
$isChecked = $req->checked;
$isSelectedValue = $req->value;
}
public function UsethoseValues()
{
if ($this->isChecked) { // this variable values is not getting updated
}
}
}
推荐答案
您需要在ValidateValue函数中使用$this
引用/更新$isChecked
属性.因此,您更新的代码应为:
You need to reference/update $isChecked
property using $this
inside ValidateValue function. So your updated code should be:
public function ValidateValue(Request $req)
{
$this->isChecked = $req->checked;
$this->isSelectedValue = $req->value;
}
这篇关于将新值重新分配给全局变量Laravel PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文