jx12345
jx12345

Reputation: 1670

RESTful MVC application

I'm writing my first MVC web application and I'm trying to keep it as textbook and RESTful as possible.

It's basically a customer ordering system. I have the following urls routing to the following controllers methods

url - controller - method

/customers customer-controller index (shows a list of all customers)

/customers/1 customer-controller view (shows the details of the customer with id = 1)

/orders order-controller index (shows a list of all orders)

/orders/1 order-controller view (shows the details of the order with order_no = 1)

what i want to do is to add a page that shows a list of the orders associated with a specific customer at the url: /customers/1/orders. What i'm not sure is which controller this should map to and to what method.

Should it go in the customers controller, in the order controller or should there be a new customer-orders controller?

Any help, advice, comments much appreciated,

thanks

jim

Upvotes: 2

Views: 530

Answers (1)

tereško
tereško

Reputation: 58444

As i see it, you are just applying a filter to the list off all orders. And for this reason it would make more sense to use Orders controller.

Also, you might rethink your routing policy. IMHO, it would be better to have something like this: /:controller((/:action)/:id), with default value index or list for the action. Here are view examples in this pattern:

/orders               << all of the orders
/orders/customer/2    << data for customer_id = 2
/orders/locations     << orders , ordered by location
/orders/customer      << orders , ordered by customer
/customers            << all curomers
/order/details/1      << info for single order with id = 1

It might be good for you to investigate how Kohana3 does the routing. For all its problems, routing is one of best feature the have.

Well .. just my two cents.

Upvotes: 2

Related Questions