[英]How to call a Global variable in controller method using CodeIgniter
I have created a global variable in the controller and then I used this variable in a method and after some process, this variable has a value, and now I want to access this variable with this value in another method IS that possible or not please tell me the solution.我在控制器中创建了一个全局变量,然后我在一个方法中使用了这个变量,经过一些过程,这个变量有一个值,现在我想在另一个方法中用这个值访问这个变量是可能还是不请告诉我的解决方案。 And if it is not the right method then please tell me how I can access a variable from one method to another in the controller My Variable is $variable
and the function is:如果它不是正确的方法,那么请告诉我如何在控制器中从一种方法访问变量到另一种方法我的变量是$variable
并且函数是:
`public function date_to_db($ui_date){
$temp = explode('/', $ui_date);
$db_date = $temp[2] . '-' . $temp[1] . '-' . $temp[0];
return $db_date; }`
You can use您可以使用
$variable = 'test';
function test()
{
global $variable;
$value = $variable;
return $value;
}
or add an index to the global array $GLOBALS['var'] = 'test';
或者给全局数组添加一个索引$GLOBALS['var'] = 'test';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.