开发者

Codeigniter: user defined helper function does not load

开发者 https://www.devze.com 2023-02-01 17:46 出处:网络
I made a custom helper extending the system string_helper.php. I placed it in my /application/helpers directory, called it MY_string_helper.php as required, unit-tested its functions.

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

I placed it in my /application/helpers directory, called it MY_string_helper.php as required, unit-tested its functions.

Now, when I try to call one of its func开发者_运维问答tions from a model, it does not work.

The functions in the default string helper work, instead. It looks like my extension is not loaded for some reasons.

Thanks a lot, and happy holidays.


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


I had the same problem. I came from windows OS development of my codeigniter project, then shifted to Ubuntu, but somehow it still didn't load my helpers.

I found that changing the naming convention to lowercase solves the problem. Don't follow what's written in the doc where you are given a prefix to insert, especially if it's in uppercase. Make use of lowercase.


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

CodeIgniter does not load Helper Files by default, so the first step in using a Helper is to load it. Once loaded, it becomes globally available in your controller and views.


Linux is case sensitive, Windows no. So, if you are development in OS Windows, before upload your system in a Linux hosting foe example, you need have the names of the files in lowcase.

For example:

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


mmm, i'm not sure it will work for helpers, but have you tried to load the helper in this way?

$CI = & get_instance();

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


I faced a similar kind of situation. My development environment was WINDOWS and it worked fine as described in the DOCs i.e. MY_string_helper.php

On the production environment of UNIX, it gave error:

Unable to load the requested file: helpers/my_form_helper.php

Changing the file name to lower case resolved this error BUT the helper was not actually loaded.

After a lot of time waste, by hit and trail it worked [ it is un-documented ]

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

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

Also, the prefix has to capital, it did not work with lower case prefix:

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


you just have to change your helper function name with your prefix like found in application/config/config.php

after helper renamed make sure it contains small letters only

then change autoload file with the function name that you renamed,

main problem because of OS like your Hosting server is linux and you develope with windows so this problem rise

0

精彩评论

暂无评论...
验证码 换一张
取 消