简体   繁体   中英

CodeIgniter, Is it possible to use an helper within a custom helper?

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

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

I get an error :

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

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');

Or you can also use the language helper:

$site_title = lang('site_title');

http://codeigniter.com/user_guide/helpers/language_helper.html

That is assuming the helper before this point. Otherwise just do as above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM