Welcome Guest, Not a member yet? Register   Sign In
Can't extend helpers
#1

[eluser]Unknown[/eluser]
Hello,

I am trying to extend the text helper so I followed the documentation:

I created a helper file named MY_text_helper.php in my /application/helpers/ folder

The "subclass prefix" setting in the config.php file is this:

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

I load the helper using the autoload.php file:
Code:
$autoload['helper'] = array('url','text');

From then on I use my custom functions.My problem is that on a Linux server, unless I rename the file to my_text_helper.php, I get this error:

Code:
Unable to load the requested file: helpers/my_text_helper.php

It seems CI doesn't like the uppercase prefix.

I used this on a Linux box using "XAMPP Linux 1.7.4" with CI 1.7.3 and PHP 5.3.5. When I ran the same code on a Windows box, everything worked.

I would like to know if it's there a way to make this prefix work properly.
#2

[eluser]CroNiX[/eluser]
Helpers aren't classes, so you can't extend them like you do a library using the MY_ prefix. They are just collections of regular functions.

Just create a new helper called whatever_helper.php and drop it in the helpers directory. Then you can load or autoload it by the name minus the _helper.php, like $this->load->helper('whatever');
#3

[eluser]WanWizard[/eluser]
Eh, not entirely true. Yes, helpers are procedural functions, and not classes. But you can 'extend' helpers as well.
It allows you to redefine helper functions (hence the function_exists() check in the helpers) as well as add your own ones.
#4

[eluser]danmontgomery[/eluser]
The root of the problem here is that the windows filesystem is not case-sensitive, whereas linux is. If you want it to work "perfectly", leave the filename lowercase everywhere.




Theme © iAndrew 2016 - Forum software by © MyBB