Modifying a Helper

So does CodeIgniter know when I've created my own helper in the Application/helpers folder - and treat that as default?

For example... the default url_helper.php in system/helpers (CI's core) has the url_title() function.

I want to modify that and create my own.

So would I create url_helper.php inside application/helpers - and then create a new function called url_title - then modify it to what I need?

It looks like - based on this line of code in the core url_helper.php - that is the case:
if ( ! function_exists('url_title')){...}

But I just want to be sure Smile

[eluser]GSV Sleeper Service[/eluser]
you're on the right track, see the section labelled "extending" helpers for full details.

Yah I broke my app tinkin around with it all..and then read up on that article..

I have it named MY_url_helper.php

I'm trying to strip the spaces out instead of giving it a dash or underscore. (lowercase == true)

So if I put in "XYZ Corp" - that function will convert it to "xyzcorp"

so I just added this bit of code between the default if/else statement:

function url_title($str, $separator = 'dash', $lowercase = FALSE)
        if ($separator == 'dash')
            $search        = '_';
            $replace    = '-';
        else if($separator == 'strip')
            $search     = ' ';
            $replace    = '';
            $search        = '-';
            $replace    = '_';

The inflector helper has a humanize() function that strips out the spaces.

Could you do something like:

$stringToAlter = "Here_Is_My_string";

$newString = strtolower(humanize($stringToAlter));

It looks like it replaces underscores with spaces...

$word = "my_dog_spot";
echo humanize($word); // Returns "My Dog Spot"

I need to remove the spaces to it returns MyDogSpot (and then I'll use the strtolower function to make it mydogspot)

$clientdir = url_title($this->input->post('clientname'), 'underscore', TRUE);
$clientdir = str_replace('_', '', $clientdir);

This returns the desired effect. Not sure if there is a better way.

Sorry, I posted the wrong function. I meant the camelize() function. The camelize() function strips out the spaces. You could combine it with the strtolower() PHP function to get the results you want.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.