Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load helper from model in CodeIgniter?

I want to load some helper in a model. How to do this? Tried to use:

${get_parent_class($this)}->load->helper ('text');

But still getting an error

Fatal error: Call to a member function helper() on a non-object

like image 323
Simon Perepelitsa Avatar asked Nov 05 '09 13:11

Simon Perepelitsa


1 Answers

GSto answered $this->load->helper('helpername') but if you are in a model's method, $this simply refers to that model's (class) instance and not to CI global. That won't work!

Instead you need to load the CI global and then load the helper:

// PHP 4
// $ci =& get_instance();
// PHP 5    
$ci = get_instance();
$ci->load->helper('text');
like image 136
mwm Avatar answered Oct 11 '22 18:10

mwm