Modifying a Helper

#1
[eluser]NateL[/eluser]
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:
Code:
if ( ! function_exists('url_title')){...}

But I just want to be sure Smile

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

http://ellislab.com/codeigniter/user-gui...lpers.html

#3
[eluser]NateL[/eluser]
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:

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

#4
[eluser]wowdezign[/eluser]
The inflector helper has a humanize() function that strips out the spaces.

Could you do something like:

Code:
$stringToAlter = "Here_Is_My_string";

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

#5
[eluser]NateL[/eluser]
It looks like it replaces underscores with spaces...

Code:
$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)

#6
[eluser]NateL[/eluser]
Code:
$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.

#7
[eluser]wowdezign[/eluser]
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.