Codeigniter: custom helper function not loading

I made a special helper extending the string_helper.php system.

I put it in my /application/helpers , naming it MY_string_helper.php as necessary, tested its functions.

Now, when I try to call one of my functions from the model, it does not work.

Instead, the functions in the auxiliary chain are executed by default. For some reason, my extension does not load.

Thanks a lot and happy holidays.


Edit: even funnier. I saved the file as categories_helper.php in the system/helpers , and when I try to load it into the model, I got the following response: * Failed to load the requested file: helpers / categories_helper.php *

+1
source share
6 answers

I had the same problem. I came from Windows OS to develop my codeigniter project, and then switched to Ubuntu, but somehow it still didn't load my helpers.

I found that changing the naming convention to lowercase solves the problem. It does not follow what is written in the document, where you are given a prefix for insertion, especially if it is in upper case. Use lowercase letters.

+3
source

The Codeigniter helpers guide describes how helpers are available only for controllers and views. It does not explicitly mention that helper functions work in models.

CodeIgniter does not download the helper files by default, so the first step in using Helper is to download it. Once downloaded, it becomes globally available in your controller and views .

+1
source

Linux is case sensitive, Windows no. So, if you are developing Windows, before you boot your system using the Linux host as an example, you will need lowercase file names.

For instance:

On Windows : application / helpers / MY_functions_helpers.php
On Linux : application / helpers / my_functions_helpers.php

+1
source

mmm, I'm not sure that it will work for helpers, but did you try to load the assistant in this way?

$CI = & get_instance();

$CI->load->helper('string');

0
source

I faced a similar situation. My development environment was WINDOWS, and it worked perfectly as described in DOCs , i.e. MY_string_helper.php

In a UNIX production environment, he gave an error:

Unable to load requested file: helpers / my_form_helper.php

Changing the file name in lowercase resolved this error BUT , the helper was not loaded.

After repeated squandering, with the help of a hit and a trail he worked [he is not documented]

In autoload.php, just include the reference to the extended helper before the default helper:

 $autoload['helper'] = array('my_string', 'string'); 

In addition, the prefix must have capital; it does not work with the lower case prefix:

 $config['subclass_prefix'] = 'MY_'; 
0
source

you just need to change the helper function name with your prefix, as shown in application / config / config.php

after the helper is renamed, make sure that it contains only small letters

then change the startup file with the name of the function you renamed,

The main problem is because of the OS, like your Linux hosting server, and you are developing with Windows, so this problem is increasing

0
source

All Articles