Welcome Guest, Not a member yet? Register   Sign In
Help with a simple route
#1

[eluser]Uplift[/eluser]
Hi,

I'm having trouble getting a route to work.

for domain.com/offers/category

category is the segment that changes, depending on whats been clicked.

This is simple with:

Code:
$route['offers/:any'] = 'pages/view/show-category';

The user an click on an item within that category and i'm struggling to do the route for this.

the uri is something like domain.com/offers/category/item-name

I'm sure it's easily done i just haven't worked it out.
#2

[eluser]marcogmonteiro[/eluser]
[quote author="Uplift" date="1340278596"]Hi,

I'm having trouble getting a route to work.

for domain.com/offers/category

category is the segment that changes, depending on whats been clicked.

This is simple with:

Code:
$route['offers/:any'] = 'pages/view/show-category';

The user an click on an item within that category and i'm struggling to do the route for this.

the uri is something like domain.com/offers/category/item-name

I'm sure it's easily done i just haven't worked it out.
[/quote]

try
Code:
$route['offers/(:any)'] = 'pages/view/$1';

or try
Code:
$route['offers/(:any)'] = 'pages/view/show-category/$1';

I don't know if you have some subfolders in your controllers folder.
#3

[eluser]Uplift[/eluser]
It's actually a separate page i'm using a cms.

Code:
$route['offers/:any']                      = 'pages/view/show-category'; // .com/offers/category
$route['offers/[changable category]/:any'] = 'pages/view/show-offer'; // .com/offers/changeable-category/item-one

That is how i would guess it, but i'm not sure of the exact way to do it.
#4

[eluser]CroNiX[/eluser]
More specific routes need to come before less specific.

Your first route has 2 segments. Your second route has 3 segments. The one with 3 segments should come before the one with 2 segments since they use the same 'offers' controller.

Routes will stop being processed as soon as there is a match found, and they are processed from top to bottom. The route segments are NOT "required", meaning if you have a route with 3 segments, like your 2nd example, and the url was 'http://yoursite.com/offers/something/something_else', it would match your first route as well as your 2nd route, so it will go with the first. That's why the more specific routes need to come first, so they will get matched first.
#5

[eluser]Uplift[/eluser]
Ahh thanks, did not know that.. problem solved, thank you Smile




Theme © iAndrew 2016 - Forum software by © MyBB