Title in url with codeigniter

0

I researched in several places how to pass the title of a post in the url using codeigniter, ex: link The only way I got so far was to use Helper url_title() , but it's time to search the error database because there is no fighting club title, but Fight Club. Then I saw that I should create a field in the database to hold the post slug to be used in the search.

I would like to know if there is another way to do this without having to tinker with the url_title() or other function.

    
asked by anonymous 13.03.2016 / 14:32

2 answers

1

I think it's best to create another field with the "fight-club" slug. So you will always find the correct result as long as you limit not having 2 records with the same slug.

This solution will work also when you have special characters. Example:

Name: Maximum Temperature

Slug: temperature-maximum or maximum-temperature (if special characters are removed).

Without the "from / to" reference it would be very difficult to find the correct record, since the slug itself has all the characters.

If you simply replace the hyphen with white, it will work in very specific situations and another problem would happen. For example, when the original name of the movie has a hyphen:

Name: Star Wars: The Awakening of Strength

Slug: star-wars-the-awakening-of-forca

If you look for "star wars the awakening of the gallows" in the bank you will not find.

    
17.03.2016 / 20:54
0

You can use the str_replace () function to remove the hyphens from the slug .

$filme = 'clube-da-luta';
str_replace('-', ' ', $filme);
//Resultado: clube da luta

To format the text, you can use ucfirst () or ucwords () .

    
15.03.2016 / 08:32