url_title |
Hi,
reading the documentation I see the url_title() function can create human-friendly URL. Using the function I can get whatever string I want but how to display it on the URL?
Url_title is also know has slug you can use this tag to turn a blog title to slugable url and save it in your database then use the slug to fetch the post. That is when you will need to send the slug to the URL.
For example https'//mysite.com/my-post-title Happy coding
Use:
PHP Code: mb_url_title($str[, $separator = '-'[, $lowercase = FALSE]]); What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Hi, probably I did not explain the problem. Here is the situation.
When I click on a certain link I call a controller that handles a product page. I want the URL to display the title of that specific product. Since i have thousands of different products I cannot use routing. I was hoping that url_title could dynamically change the URL based on the page title. But maybe I'm wrong. If so, how to go about it? Thanks
Then what you need to do is add a field to your table of products called slug varchar 255 you use url_title to create the slug
this way you can display it into the url. Here is a helper I have for making the slugs. PHP Code: ** You will need to create a route for your products to use the slug. You can see how to do the routing here on @Includebeer's website. How to build a basic web application with CodeIgniter 4 (part 3) If you look at his url for this page you will see what can be done. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(12-17-2020, 07:53 AM)InsiteFX Wrote: Then what you need to do is add a field to your table of products called slug varchar 255 you use url_title to create the slug Ok, thanks a lot! I'll give it a try |
Welcome Guest, Not a member yet? Register Sign In |