views:

809

answers:

2

I'm new to MVC, being RESTful, and CodeIgniter and I'm trying to get into it in my spare time, so this is largely an academic question. I'm trying to build a url that will display the availability of a particular hotel room, for a particular hotel. I figured the RESTful way to do this would be

http://url/Hotel/2/RoomAvailability/3/
  • "Hotel" is the controller
  • "2" is the hotel ID
  • "RoomAvailability" is the Method
  • "3" is the Room ID

How would I set up my controller in codeigniter to handle this? Currently I'm thinking i could either

  • Do something with mod_rewrite to redirect to the RoomAvailability() method
  • Do something with the index() method and redirect to the RoomAvailability() method

Really this is a pretty generic question, as I just want to be able to do

http://url/model/method-argument/method-name/more-method-arguments

But I'm honestly having a hard time coming up with search terms to find out what to use, other than "RESTful" and "CodeIgniter", which havent been too helpful.

I'm really just looking for guidance, not for someone to write my controller for me, thanks! Also, if this URL that I'm going for is horrible and not RESTful at all, please feel free to point out a better way.

+2  A: 

Checkout the CI User Guide, specifically the part on routing.

http://codeigniter.com/user_guide/general/routing.html

davethegr8
This sounds very promising, I'll check it out, thanks!
Allen
+3  A: 

What about this url set up:

http://url/hotel/method/hotel_id/room_id

Then you could do something like this:

class Hotel extends Controller {

 function RoomAvailability() {
   $hotel = url_segment(3);
   $room = url_segment(4);
   do_magic();
 }

}
Jayrox
I thought about that, but is this considered restful? I thought to be considered restful you would have to have something in the order I had it. As in "a Hotel's (this hotel id) Room's (this room id) availability". I may be completely wrong though.
Allen
well in that case, using the routes is probably the best way. routes are very easy to set up in codeigniter. $route["hotel/:num/RoomAvailability/:num"] = 'RoomAvailabilityClass'; might get you going
Jayrox
Changed the accepted answer, that route is EXACTLY what I needed, it works great now, thanks!
Allen