phpcodeigniterrestcodeigniter-routing

How would I generate / parse this RESTful url in codeigniter


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/

How would I set up my controller in codeigniter to handle this? Currently I'm thinking I could do either of the following:

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.


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