tags:

views:

55

answers:

3

I was used to putting id's in the URL to map to an item in the database:

/hotels/1

but what if I want to get the name of the hotel with an id of 1 and put it in the URL and replace spaces with hyphens?

/hotels/hotel-bianca

I am using Kohana and there is the concept of routing (which is pretty much present in all MVC frameworks), but I can't seem to get it working

How do I go about doing this?

+1  A: 

Since I know nothing about kohana, I am going to present a possible PHP answer.

Could you pass the id through the URL and request it with PHP, and if you're passing the name of the hotel, have that correspond to the item in the database with the hotel-name as its field?

Anthony Forloney
A: 

For this purpose I use special field in db table named url :) So for example /controller/open/urladress will look for url field with 'urladress' inside to open :D I don't think you can change uri on fly)

kfedorov
A: 

In the controller you could search the database for the name. I am used to Kohana 2.3.4 with ORM so this is how I would do it:

// first you need to replace all hyphens with spaces
$name = str_replace('-', ' ', $parameter);

// search your db for the hotel by name
$hotel = ORM::factory('hotel')->where('name', $name)->find();

// check to make sure it is loaded
if ( ! $hotel->loaded)
{
    // Do something i.e. 404 page or let them know it wasn't found
}

This would let you specify by name. You could also add a check to see if the parameter was integer or not and search by id if it was.

slacker