Question

I'm new to MVC, being RESTful, and CodeIgniter. I'm trying to get into them 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 the following:

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 do either of the following:

  • 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 the following:

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

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 helpful0.

I'm really just looking for guidance; not for someone to write my controller for me. 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.

Was it helpful?

Solution

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();
 }

}

OTHER TIPS

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

https://www.codeigniter.com/user_guide/general/routing.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top