Routes with a variable - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Routes with a variable (/showthread.php?tid=73652) |
Routes with a variable - cybersven - 05-18-2019 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 ? RE: Routes with a variable - php_rocs - 05-18-2019 @cybersven, This link should assist you: https://codeigniter.com/user_guide/general/routing.html?highlight=route#setting-your-own-routing-rules RE: Routes with a variable - cpltz - 05-18-2019 (05-18-2019, 07:26 AM)cybersven Wrote: Hi, when you save url fro title, try this https://codeigniter.com/user_guide/helpers/url_helper.html?highlight=url_title#url_title $title = "499 33rd Ave Apt 208, San Francisco, CA 94121"; $url_title = url_title($title,'-',true); RE: Routes with a variable - hollax - 05-19-2019 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) |