我想在csrf
的帮助函数中返回一个Codeigniter
。
但是$this
键不能根据this post
我尝试使用$CI =& get_instance();
,但给了我未定义的变量:CI
请参见以下代码
if ( !function_exists('refresh_token')){
$CI =& get_instance();
function refresh_token(){
return $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);
}
错误:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: CI
我看到很多帖子,他们都建议使用get_instance()
,但是如果有问题请先教我。