![]() |
My routes aren't passing arguments - 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: My routes aren't passing arguments (/showthread.php?tid=3315) |
My routes aren't passing arguments - El Forum - 09-24-2007 [eluser]NSGReaper[/eluser] So I'm currently working on the file download script for a site. Files can be downloaded either by using: http://mysite/download/34 or http://mysite/download/project.pdf. That is the plan at least, these should be routed to files/getbyid and files/getbyname respectively but while I know that the right function is called no arguments are being passed to it. Code: $route['download/:num'] = "files/getbyid"; Code: class Files extends Controller { With it setup like this I always get the die() message. I have been able to make it work using regex like so: Code: $route['download/([0-9]*)'] = "files/getbyid/$1"; However it was my understanding that these were synonymous. Have I misunderstood the user guide or is something wrong? My routes aren't passing arguments - El Forum - 09-24-2007 [eluser]MikePearce[/eluser] You have to use the regex if you want to pass things to the controllers. Just using the :num and :any is just a means of mapping one URL to another when you don't know what the first URL might be. My routes aren't passing arguments - El Forum - 09-24-2007 [eluser]NSGReaper[/eluser] Thanks, I guess I made an assumption rather than misunderstood. Anyway, using regex it works beautifully. My routes aren't passing arguments - El Forum - 09-24-2007 [eluser]alpar[/eluser] Code: $route['download/(:num)'] = "files/getbyid/$1"; also works My routes aren't passing arguments - El Forum - 09-24-2007 [eluser]NSGReaper[/eluser] Ah, thanks alpar. I was hoping to find an elegant solution. I think I understand it now too. |