Twig和Codeigniter错误:在null上调用成员函数flashdata()

时间:2017-01-30 16:09:18

标签: php codeigniter twig codeigniter-3

我正在尝试在twig库中添加codeigniter函数$this->session->flashdata()。但我收到了以下错误:

Type: Error
Message: Call to a member function flashdata() on null

我在twig库的代码是:

$this->twig->addFunction(new Twig_SimpleFunction('flash_data', function($data){return $this->session->flashdata($data);}));

在我的twig文件中,我这样称呼:{{ flash_data('login_error') }}

1 个答案:

答案 0 :(得分:1)

$this->twig->addFunction(new Twig_SimpleFunction('flash_data', function($data){

$obj =& get_instance();

return $obj->session->flashdata($data);

}));