Title in url with codeigniter

Asked

Viewed 274 times

0

I searched several places to pass a post title in the url using codeigniter, ex: http://Sirc/filmes/listar/clube-da-luta The only way I could so far was to use the Helper url_title(), but it’s time to search the bank for error because there is no club-of-fight title, but Fight Club. Then I saw that I should create a field in the database to contain the post Slug to be used in the search.

I was wondering if there’s any other way to do this without having to go through the bank, using url_title() or other function.

2 answers

1


I believe that the best thing is 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 also work when you have special characters. Example:

Name: Maximum Temperature

Slug: temperature-maxima or temperature-mxima (if you take out the special characters).

Without the "from/to" reference it would be very difficult to find the correct record, because Slug has all the characteristics.

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

Name: Star-Wars: The Force Awakens

Slug: star-Wars-the-wake-of-the-gallows

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

  • Really in these cases with hyphen or even with subtlety separated by two points would not work.

0

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

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.