storm_buster
storm_buster

Reputation: 7568

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

Upvotes: 1

Views: 2054

Answers (2)

Eric
Eric

Reputation: 1197

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.

Upvotes: 0

Dan Murfitt
Dan Murfitt

Reputation: 1039

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

Upvotes: 9

Related Questions