Routes with a variable |
Hi,
Actually, I'm using routes like this : $route['property-sheet/(:num)'] = 'home/property-sheet/$1'; My question, I would like to use a variable which will be stored in db or automatically generated and based on a title previously chosen by a user. For example : Title : 499 33rd Ave Apt 208, San Francisco, CA 94121 Url wanted : https: //myWebSite.com/property-sheet/499-33rd-Ave-Apt-208_San-Francisco_CA_94121 How can I do ? (05-18-2019, 07:26 AM)cybersven Wrote: Hi, when you save url fro title, try this https://codeigniter.com/user_guide/helpe...#url_title $title = "499 33rd Ave Apt 208, San Francisco, CA 94121"; $url_title = url_title($title,'-',true);
Change route rule to
PHP Code: $route['property-sheet/(:any)'] = 'home/property-sheet/$1'; In your views or places to show url PHP Code: echo site_url('propert-sheet/'.url_title(property->title)) Bonus: I would suggest you have another column e.g slug Where you will save URL formatted titles so that you don't have to call url_title() every time Instead your code would be PHP Code: echo site_url('propert-sheet/'.property->slug) |
Welcome Guest, Not a member yet? Register Sign In |