Delving into Routes... Help! - 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: Delving into Routes... Help! (/showthread.php?tid=28228) |
Delving into Routes... Help! - El Forum - 03-05-2010 [eluser]JamesTaylor[/eluser] I have just delved into using routes for the 1st time, i've got things working as i expect they should but i don't think i've done it very effeciently! In my contoller named Menus i have an index function which is displaying a front end form for the user and determining what info should be shown, what function the form should perform - insert new record or edit existing (it is part of an admin section). If the form is inserting it submits to the insert function within this controller, when its editing / updating it submits to the update function. In the controller i then have additional functions to actually perform the insertion, updating and deleting of records. here's the controller (in summery to save on the character limit!): Code: <?php On the index function because it is catching variables from the url segments it wasn't running the 'index' function and was instead looking for a corresponding function. for example if the URL came in as .../Menus/PubName/MenuType/MenuCat the idea is that the PubName / MenuType / MenuCat were caught as variables - but it was trying to run the function 'PubName' As i wanted to keep my URL cleaner and without the .../Menus/index/... i set up my 1st route! Code: $route['Admin/Menus/(:any)'] = "Admin/Menus/index/$1"; but i soon realised that meant every URL was getting routed to the index function so i started adding more routes and have ended up with the following: Code: $route['Admin/Menus/Insert'] = "Admin/Menus/insert"; The routes work and everything behaves as i expect but i figure i haven't really implemented this effectively so was hoping people would offer me some advice and show me where i've gone wrong! I am i right in thinking that the main problem lies in the fact i'm using the index function? if i changed that name to 'view' then i wouldn't need any routes at all, but i would end up with view in my URL's which isn't actually needed? James Delving into Routes... Help! - El Forum - 03-05-2010 [eluser]Valdis Ozols[/eluser] If that works as supposed then it seems ok taking into account that there are only few routes defined. Delving into Routes... Help! - El Forum - 03-05-2010 [eluser]JamesTaylor[/eluser] yes it's good that it works, but i think that by creating my 1st route it has actually generated the need for the other 6 routes... which makes me think i haven't implemented it very effectively - i.e adding 1 route has caused me problems on 6 other routes? Delving into Routes... Help! - El Forum - 03-05-2010 [eluser]JamesTaylor[/eluser] My current setup has also meant i have to set routes which are identical to the the original URL: Code: $route['Admin/Menus/Update'] = "Admin/Menus/Update"; |