我正在写我的自定义助手.我试着使用语言助手:
$this->lang->line('site_title')
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
Fatal error: Using $this when not in object context in
C:\Users\guest\Wamp\www\codeIgniter\application\helpers\blog_helper.php on line 15
Run Code Online (Sandbox Code Playgroud)
如果要在帮助程序(或自定义库)中调用CodeIgniter超级对象中的方法,则需要使用该get_instance()函数.这将引用CodeIgniter超级对象到变量$ ci - 所以你可以通过使用$ci而不是$this:来调用CodeIgniter方法:
$ci =& get_instance();
$site_title = $ci->lang->line('site_title');
Run Code Online (Sandbox Code Playgroud)