![]() |
Beginner question - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Beginner question (/showthread.php?tid=31503) |
Beginner question - El Forum - 06-22-2010 [eluser]Christophe28[/eluser] Hi, I have a beginner question. I'd like to create a uri like /photos/username/photo_id So I have create a controller called Photos. But how do I have to call the function? The username is different every time ... So far I have found how to get a segment from the uri to pass to the database ($this->uri->segment(1) ![]() I hope somebody has some time to help me ![]() Christophe Beginner question - El Forum - 06-22-2010 [eluser]Clooner[/eluser] Go into the routes.php file in your application/config dir add this line! Code: $route['/photos/(:any)/(:num)'] = 'photos_controller/myphotofunc/$1,$2'; in your photos_controller create the function like Code: function myphotofun($username, $photo_id) Beginner question - El Forum - 06-22-2010 [eluser]Christophe28[/eluser] Hi, Thank you for your response. I have added the following line in routes.php Code: $route['photos/(:any)/(:any)'] = 'photos/photofunction/$1,$2'; And added the following line in controller.php Code: function photofunction($username, $caption) But got the following warning when surfing to /photos/Christophe/mygreatphoto Quote:A PHP Error was encountered I have changed a bit here and there, like ID to caption. I think this is ok? What am I missing here? Dank je voor je hulp ![]() Christophe Beginner question - El Forum - 06-22-2010 [eluser]Clooner[/eluser] [quote author="Christophe28" date="1277229863"]Hi, Thank you for your response. I have added the following line in routes.php Code: $route['photos/(:any)/(:any)'] = 'photos/photofunction/$1,$2'; And added the following line in controller.php Code: function photofunction($username, $caption) But got the following warning when surfing to /photos/Christophe/mygreatphoto Quote:A PHP Error was encountered I have changed a bit here and there, like ID to caption. I think this is ok? What am I missing here? Dank je voor je hulp ![]() Christophe[/quote] The error says it can't find the second argument of. try this Code: function photofunction($username='geen', $caption='leeg') and I believe the routes should be like this: Code: $route['photos/(:any)/(:any)'] = 'photos/photofunction/$1/$2'; Beginner question - El Forum - 06-22-2010 [eluser]Christophe28[/eluser] Yep, changed the routes and it works! Thx mate ;-) |