Welcome Guest, Not a member yet? Register   Sign In
Anyway to completety remove controller name for some controller?
#1

[eluser]aquary[/eluser]
I've developed a hotels website which contains hotels information, tourist spots, and other things related. The current URL is like,

http://myhotel.com/hotel-detail/hotel-name

This URL would go to /hotel/detail/hotel-name

The site is not launched yet, but now the requirement for the URL has changed into something like this

http://myhotel.com/the-country-of-hotel/...hotel-name (the hotel main page)
http://myhotel.com/the-country-of-hotel/...-room-rate (the roomrate of the hotel)
http://myhotel.com/the-country-of-hotel/...me-gallery (the gallery)
http://myhotel.com/the-country-of-hotel/...hotel-name-......

Is it possible for CI to do something like that? I don't know how could I archive the using re-routing alone. I thought about using country name as a word to be looked for like this

$route['(USA/Britain/Japan)/(:any)')="hotel/detail/$1/$2";

But everything except the domain name come from database so this is not a choice for me.

More than that, the same pattern is also applied to other sections of the site

http://myhotel.com/country-name (All hotels in that country, I think)
http://myhotel.com/country-name/city-name (same with above, but city come into play)

How can I solve this problem? Or should I tell them "I need some "static" words in those URL" ?

Thanks Smile.
#2

[eluser]Zeeshan Rasool[/eluser]
You can do it by enabling query string in codeigniter. May be this can help you..
Enabling query string in codeigniter
#3

[eluser]Mike Ryan[/eluser]
Hi,

You could use routing to do this by redirecting all requests to a Search controller. A very basic example would be:
Code:
$route['(:any)/') = "hotel/country_search/$1";
$route['(:any)/(:any)/') = "hotel/city_search/$1/$2";
$route['(:any)/(:any)/(:any)') = "hotel/hotel_search/$1/$2/$3";

In your controller you could then do a DB search (example query: "...WHERE country='$1' and city='$2'..."). If there is only one result, return the "Detail" page for that hotel. If there is more than one result, return a Search Results page containing the list of hotels. This pattern would also work for myhotel.com/uk/london and myhotel.com/uk.

"http://myhotel.com/the-country-of-hotel/the-city-of-hotel/hotel-name-room-rate" Could be a problem, as you will have to make sure your chosen delimiter is not used in a hotel name. Do you think you could suggest this instead:

http://myhotel.com/the-country-of-hotel/.../room-rate
http://myhotel.com/the-country-of-hotel/...me/gallery

Routing supports regular expressions so you can get as complicated as you want to, but this would be much easier to implement.
#4

[eluser]aquary[/eluser]
Thanks for your reply

$route['(:any)/') = "hotel/country_search/$1";
$route['(:any)/(:any)/') = "hotel/city_search/$1/$2";
$route['(:any)/(:any)/(:any)') = "hotel/hotel_search/$1/$2/$3";

The problem with this one is that I also have other controllers in the system too, articles, members, destinations, etc.... If I use that, all of the link will go to the hotel controller. The easiest way I can do here is having some static word like,

http://myhotel.com/hotel-in/country/city/hotelname

That would be a lot easier for me....
#5

[eluser]Mike Ryan[/eluser]
Yes, a static word would make it a lot easier. "hotel-in/england" would probably be a good link SEO-wise too.

I'm not sure if you know, but routes are executed in the order stated in the config file. So if you had:
Code:
$route['members'] = "members/";
$route[’(:any)/’) = “hotel/country_search/$1”;
...

it would all still work. However hardcoding all the other controller names does not seem like the "best" way to do it, so a static word is probably the best way to go. Hopefully someone who knows more about routing than we do will chip in with a nice clean method of achieving your goal. :-)




Theme © iAndrew 2016 - Forum software by © MyBB