CodeIgniter,是否可以在自定义助手中使用助手? [英] CodeIgniter, Is it possible to use an helper within a custom helper?

查看:150
本文介绍了CodeIgniter,是否可以在自定义助手中使用助手?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写我的自定义助手。我尝试使用语言助手:

I am writting my custom helper. I tried to use the language helper:

$this->lang->line('site_title')

我收到错误:

Fatal error: Using $this when not in object context in
C:\Users\guest\Wamp\www\codeIgniter\application\helpers\blog_helper.php on line 15


推荐答案

如果你想从CodeIgniter在一个助手(或一个自定义库)中的超级对象,你需要使用 get_instance()函数。这将引用CodeIgniter超级对象到变量$ ci - 所以你可以通过使用 $ ci 而不是 $ this

If you want to call methods from the CodeIgniter super object within a helper (or a custom library) you'll need to use the get_instance() function. This will reference the CodeIgniter super object to the variable $ci - so you can call the CodeIgniter methods by using $ci rather than $this:

$ci =& get_instance();
$site_title = $ci->lang->line('site_title');

这篇关于CodeIgniter,是否可以在自定义助手中使用助手?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆