Php get_实例在codeigniter助手函数中不起作用
我想在Php get_实例在codeigniter助手函数中不起作用,php,codeigniter,helper,Php,Codeigniter,Helper,我想在Codeigniter中的助手函数中返回一个csrf 但是,$此键不能根据 我尝试使用$CI=&get_instance(),但给我未定义的变量:CI 请参阅下面的代码 如果(!function_存在('refresh_token')){ $CI=&get_instance(); 函数刷新\u令牌(){ 返回$CI->security->get_csrf_hash(); } } 控制器: public function delete_data(){ $token = ref
Codeigniter
中的助手函数中返回一个csrf
但是,$此
键不能根据
我尝试使用$CI=&get_instance()代码>,但给我未定义的变量:CI
请参阅下面的代码
如果(!function_存在('refresh_token')){
$CI=&get_instance();
函数刷新\u令牌(){
返回$CI->security->get_csrf_hash();
}
}
控制器:
public function delete_data(){
$token = refresh_token();
$array = array(
$this->security->get_csrf_token_name() => $token,
'data'=> "hi",
);
echo json_encode($array);
}
错误:
遇到PHP错误
严重性:通知
消息:未定义变量:CI
我看到很多帖子,他们都建议使用
get_instance()
,但请提前教我是否出错。函数在PHP中有自己的作用域,您必须将CI传递到函数中或在函数中声明它
e、 g
请查看以获取更多信息
if ( !function_exists('refresh_token'))
{
function refresh_token()
{
$CI = get_instance();
return $CI->security->get_csrf_hash() ;
}
}