Welcome Guest, Not a member yet? Register   Sign In
Move first segment to last segment?
#1

[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?
#2

[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.
#3

[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.
#4

[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 still can use the segment using this->uri->segment(1).

You better limit the route as much as possible otherwise it could have unwanted effects.
#5

[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 still can use the segment using this->uri->segment(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:
(.+)
would take the rest of the URI regardless of its content and length?

Also, could you elaborate on what you mean by limiting the route to avoid "unwanted effects"?

Thanks again!
#6

[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';
#7

[eluser]thesf[/eluser]
Ok thanks. I'll try this out.




Theme © iAndrew 2016 - Forum software by © MyBB