How to load assistant from model in CodeIgniter?

I want to load some helper into the model. How to do it? Tried to use:

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

But still a mistake:

Fatal error: function-member-function () call for a non-object

+6
php class codeigniter
source share
4 answers
 $this->load->helper('helpername') 
-3
source share

GSto responded with $this->load->helper('helpername') , but if you are in the model method, $this just refers to an instance of the model (class), not the global CI. This will not work!

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

 // PHP 4 // $ci =& get_instance(); // PHP 5 $ci = get_instance(); $ci->load->helper('text'); 
+29
source share

You do not need to load the helper in the model. Just load the helper into the controller and use the function in the model, and we usually use a helper function in the controller

0
source share

I think CI does not check auxiliary duplication ... CI herrpers are procedural files, you can enable ur helper twice if ur controller has the same helper loaded as ur model (which is loaded into this controller). Maybe instead of a library ...

I see that I get a negative vote without comment ... by checking the loader class from the CI kernel, u can see that the helpers method does not check if the helper has been added before (it is not included in the is_loaded () array like most classes loaded using the load factory class) ... I do not recommend in any case loading handlers in both models and controllers ... for ex, I made a helper to output the encoding that I use in controllers (before I pass view data). It would be very bad if I changed the view state twice ...

-3
source share

All Articles