CodeIgniter Forums
What is the right way to load own helpers - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: What is the right way to load own helpers (/showthread.php?tid=43583)



What is the right way to load own helpers - El Forum - 07-17-2011

[eluser]Unknown[/eluser]
I am new in codeigniter. using version 2.0.2

I am trying to load my own helper file from application/helpers folder.
but codeigniter show me error : Unable to load the requested file: helpers/common_helper.php

after some debugging i found that the loader class is looking for that file first in
application/helpers folder if it exists then system/helpers folder. but there is not such file so it generating the error.
i made some change in the loader file as following :

Code:
/*Original code Line No 759  */
if ( ! file_exists($baseclass))
{
    log_message('error', "Unable to load the requested class: ".$class);
    show_error("Unable to load the requested class: ".$class);
}

change to:
moving the include statement from line 785 in this condition.
Code:
if ( file_exists($baseclass))
{
    include_once($baseclass);
}

now it working fine with me.

is it OK? i don't know.

can any one help me please.
thanks in advance


What is the right way to load own helpers - El Forum - 07-17-2011

[eluser]Aziz Chouhan[/eluser]
hi hasib

for your problem i recommend that visit to the above link

http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html

this will help you to create your own library and load and call as per required.

if you have any problem then reply


What is the right way to load own helpers - El Forum - 07-17-2011

[eluser]Aken[/eluser]
You likely named your helper file incorrectly. CodeIgniter looks for a specific structure when it comes to the file name. In your case, it is looking for the file "common_helper.php" in the "application/helpers/" folder. If you rename your file to that, everything will work fine. There is zero need to modify the Loader library.