Welcome Guest, Not a member yet? Register   Sign In
Routes with a variable
#1

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 ?
Reply
#2

@cybersven,

This link should assist you: https://codeigniter.com/user_guide/gener...ting-rules
Reply
#3

(05-18-2019, 07:26 AM)cybersven Wrote: 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 ?

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);
Reply
#4

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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB