2

As an example of what I am trying to ask, let's say that the user wants to delete an address from their account.

My workflow for my AJAX actions are basically:

  1. User clicks submit and the id of the stored address is sent to the controller
  2. The controller makes sure the user can perform the action (each user has different permissions)
  3. The controller makes sure that the id of the address given was attached to their account
  4. Any errors that were encounters are sent back and displayed to the user or the address was deleted and a success message is shown.

I am really having a hard time wrapping my head around what the proper MVC execution path for this would be. Can anybody help me out?

4
  • Why don't you try a MCV framework like Backbone? Free backbone eBook Commented Dec 16, 2013 at 17:10
  • 1
    @jantimon: Because Backbone isn't MVC... No framework is really. If anything, your code should implement MVC, not a framework. Commented Dec 16, 2013 at 17:18
  • @jantimon how about you read the free ebook link you gave, it clearly tells you about how backbone is not a MVC.. Commented Dec 16, 2013 at 17:23
  • I am making all of my new code MVC and will eventually go back and convert all the existing code to use the pattern. Commented Dec 16, 2013 at 17:25

1 Answer 1

3

Actually, it should be something like:

  1. User clicks submit and the id of the stored address is sent to the controller
  2. The controller makes sure the user can perform the action (each user has different permissions)
  3. The controller queries the Model layer to associate the ID of the address given with the user's account.
  4. The controller invokes a View, which in turn invokes a template (since this is AJAX, it'll probably be a JSON template) which returns whatever state to the user (error, success). If you want to get really fancy, send a proper response code header as well.
  5. Client gets JSON response from AJAX and takes proper action.
Sign up to request clarification or add additional context in comments.

7 Comments

Would it make sense for a service method to return an array of error strings or true on success?
@nathanjosiah: No. Your return value should be uniform. It should throw some sort of Exception on error, which is then caught by the caller.
@Mandara How would multiple errors be handled with that method though?
@nathanjosiah: One at a time. What examples for multiple errors do you have?
@Mandara I was thinking of adding data. In that case would the controller be creating the entity and using the service to store it? If so, does it make sense that the controller is handling the errors from the entity creation?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.