I'am planning my website over here based on MVC.

And I am thinking about a webservice (who knows, maybe one day I'll create an android app or something).

The site and the webservice will behave diferently from each other.

So what should I do? Write different controllers for each... or stuff IFs all over the place?

For example: on the site, the controller will act as such:
Password correct?
---->redirect user to welcome screen
Password incorrect?
---->render login page again

But the webservice will simple show a json like:
{message: 'wrong password/sucess'}

Which one you think is the best approach?

closed as too broad by GlenH7, Kilian Foth, user40980, Dynamic, World Engineer Mar 31 '14 at 18:37

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Seperate the controllers, this is the way I use. That makes things easier when you have larger operations. – Knerd Mar 27 '14 at 14:58
  • +1. Separate controllers for API and NON-API calls. API Controllers will be a lot ligher in general without the view rendering part (unless you count returning data as .json as a view). – user120925 Mar 27 '14 at 15:04
  • yes edvinas.me, it is exactly what I was thinking, returning the json as a view. thank you for your suggestion – Adinan Mar 27 '14 at 15:49

Your "stuff IFs all over the place?" question sort of answers itself. That's obviously not a good design.

You should separate the controllers, but have them rely on a common code base for shared actions. For example, you should only have one place in your code that verifies a password. Each controller should call this code and then respond with the appropriate behavior based on the context of that controller.

Not the answer you're looking for? Browse other questions tagged or ask your own question.