Building Codeigniter URLs with variable segments |
[eluser]vikrantsharma1[/eluser]
I have searched for the solution to my problem in CI user guide but couldn't find any. So, here is my problem. I need to build SEO friendly URLs. I have a controller called "Outlets" and the view that I need to generate will have a URL structure like http://www.mysite.com/[city_name]/[area_name]/[outlet_name]. The URL segments city and area are fields in their respective tables and outlet_name is a field in the table "Outlets". Thanks for your help.
[eluser]Glazz[/eluser]
Have you read http://ellislab.com/codeigniter/user-gui...uting.html ?
[eluser]vikrantsharma1[/eluser]
[quote author="Glazz" date="1339279971"]Have you read http://ellislab.com/codeigniter/user-gui...uting.html ?[/quote] Yes, and I am able to generate a URL like http://www.mysite.com/outlets/123 but how do I add the city and area name to the URL?
[eluser]InsiteFX[/eluser]
Code: ------------- Segments 1 2 3 4 By default it will return FALSE if the segment is empty. CodeIgniter Users Guide - URI Class
[eluser]vikrantsharma1[/eluser]
[quote author="InsiteFX" date="1339286903"] Code: ------------- Segments 1 2 3 4 Thanks for responding. Actually, I am new to this routes thing and pretty confused. As far as my understanding goes, the function that you have built will retrieve URI segments and based on that some results can be shown. My question is slightly different and let me try to explain it again. Let's say I generate a list of all outlets with Code: $query = $this->db->select('outlet_name')->from('outlets')->limit(10, 0) Each of this link should look like http://www.mysite.com/[outlets]/[city_name]/[area_name]/[outlet_name]. My question is how do I generate such a link?
[eluser]InsiteFX[/eluser]
You will need to use the names form your foreach loop. Code: <?php echo anchor('site/'.$city_name, 'My Cities', 'title="Cities"'); ?>
|
Welcome Guest, Not a member yet? Register Sign In |