简体   繁体   中英

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:

`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';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM