![]() |
Move first segment to last segment? - 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: Move first segment to last segment? (/showthread.php?tid=16762) |
Move first segment to last segment? - El Forum - 03-16-2009 [eluser]thesf[/eluser] Hey, I'm in the process of writing a project management application with CI and I'm wondering what the best way to achieve something is... Basically, I want to move the first segment of the URI to the end of a re-routed URI while also insuring that it isn't interpreted as a class or function. Normally this would be easily achieved with URI routing but to complicate it a little I can make no assumptions about what the URI will contain. In other words, I don't know how many segments there will be or what they will contain therefore URI routing is not an option (or at least I don't think it is? Please correct me if I'm wrong!) To give this some context... the URI will look something like /projectID/module/controller/function/var/iab/les/ (this is where the ambiguity comes in as there can be any number of variables added onto the URI) and I want to move the project ID to the end so that the controller and function can be called. Any ideas? Move first segment to last segment? - El Forum - 03-16-2009 [eluser]TheFuzzy0ne[/eluser] I'm not sure if what you're trying to do is a) possible, or b) the best approach. However, please check out my [url="http://ellislab.com/forums/viewthread/106502/"]Alternate URI Syntax library[/url]. I created it for such occasions. Move first segment to last segment? - El Forum - 03-16-2009 [eluser]jedd[/eluser] Quote:To give this some context... the URI will look something like /projectID/module/controller/function/var/iab/les/ (this is where the ambiguity comes in as there can be any number of variables added onto the URI) and I want to move the project ID to the end so that the controller and function can be called. Hi thesf, First preference would be to not have to do this wrangling. Do you control where these 'arriving' URLs are being generated, and/or how they are? My second preference would be to avoid routes (or at least the complex ones you may be looking at writing) and prefix the arrival URL's with something that will throw it straight into a dedicated controller that can more intelligently re-mangle your URL and then redirect you to the right place. It'd pretty ugly though. Move first segment to last segment? - El Forum - 03-16-2009 [eluser]xwero[/eluser] The module segment is a directory? You don't even have to move the segment to the end of the url, just make it invisible for the router. Code: $route['\d+/(.+)'] = '$1'; You better limit the route as much as possible otherwise it could have unwanted effects. Move first segment to last segment? - El Forum - 03-16-2009 [eluser]thesf[/eluser] Thanks for the replies! [quote author="xwero" date="1237232612"]The module segment is a directory? You don't even have to move the segment to the end of the url, just make it invisible for the router. Code: $route['\d+/(.+)'] = '$1'; You better limit the route as much as possible otherwise it could have unwanted effects.[/quote] Sorry, yeh I'm also using the Modular Extensions library so the module segment would be a directory yes. Hiding instead of moving is a very good point. I had totally overlooked that! So I'm assuming Code: (.+) Also, could you elaborate on what you mean by limiting the route to avoid "unwanted effects"? Thanks again! Move first segment to last segment? - El Forum - 03-16-2009 [eluser]xwero[/eluser] You are right about the regex. If the only module that needs the routing is clients for example the route would be Code: $route['\d+/(clients)/(.+)'] = '$1/$2'; Move first segment to last segment? - El Forum - 03-16-2009 [eluser]thesf[/eluser] Ok thanks. I'll try this out. |