RESTful API MVCs, Multiple Models, and General Views

Preface: The following text is of decent size because I tried to maximize value for other readers with similar, fundamental, and conceptual questions.


Introduction

I am currently developing a web-based event management tool that uses the Laravel MVC framework to maintain a proper application framework and facilitate development.

The goals of the app are to

  • provide an effective way to create (respectively CRUD) events.
  • invite registered users to these events
  • allow users to confirm their participation in previously created events

Following the MVC pattern, I created

  • Model named Event
  • a EventController
  • multiple views
    • static Event viewing, displaying existing events
    • view of the form for creating and editing with the name eventForm
    • eventIndex , a list of all events

Up to this point, everything seemed relatively straightforward, but I ran into design issues when I tried to implement additional features so that users could confirm their participation in certain events.

Additional Information

For further clarification, each Event has several attributes (some are omitted):

  • Title
  • Description
  • Multiple EventDate s consisting of the following attributes:
    • Title
    • The time interval (for example, 09-20-2013 from 09:00 to 09-20-2013 17:00).

The aforementioned EventDate also a model with a corresponding database table.

Differences from the account with which the user is logged in, I made the $admin boolean variable available to all views and controllers, which is used to change the appearance of the Event as follows:

  • $ admin = true: The view is a static page displaying the Event and EventDate in a table
  • $ admin = false: In addition, the view has a hidden form and buttons for each row of the EventDate table, allowing users to confirm or reject their participation in each of EventDate s

Using a variable and @ if...@endif blocks to change the view seems acceptable to me, because, despite the hidden form, the differences between user and administrative modes are quite small.

Problem

Now the problem I'm stuck for is this:

Who is responsible for processing POSTed hidden form data in user mode?

Firstly, here are a few facts for the current state of development:

  • Event controller currently offers the following features:

     /* CRUD functions */ public function CreateEvent() public function ShowEvent($id) public function UpdateEvent($id) public function DeleteEvent($id) /* Form display helpers */ public function NewEvent() public function EditEvent() 
  • The EventDate model EventDate separate from the Event model because Event has multiple EventDate s
  • Acknowledgments are saved for each user and EventDate in another separate table linked to the EventDateConfirmation model EventDateConfirmation

Decision is coming

Here are the options I have:

  • EventController , which must be extended using methods like CreateEventDateConfirmation() , etc., which leads to several CRUD methods that do not even belong to this controller, since they are not considered directly in the Event model and no changes occur at all in the events table

  • In a separate EventDateConfirmationController , which is responsible only for receiving and configuring data for the EventDateConfirmation model with two possible uses:

    • Calling EventDateConfirmationControler methods from EventController with a few clumsy

       Controller::resolve(DEFAULT_BUNDLE,'EventDateConfirmationController')->CreateConfirmation($params); 
    • Setting up a route that responds to a hidden view of a POST request for the corresponding EventDateConfirmationController action directly

    The first possibility has the disadvantage of calling an external controller in an unpleasant way, which seems wrong to me, the second is impractical when the form also contains data that belongs directly to the event, and therefore the Event controller should be processed

  • ??

In my opinion, neither # 1, nor # 2 are good solutions to the problem, as they seem to be hacked and don't fit very well into the MVC pattern.

What alternatives are available that would be a clean solution to this problem?

Thank you in advance!

+4
source share
1 answer

I think that you could make No. 2 and make it a little less hacked, but still do not need to change much. Otherwise, I believe that No. 1 is not the best choice.

Actually, what would I do if I were in your circumstances, create an EventDateConfirmationController and in User-Mode make it a separate form, which is asynchronous ajax. Either submit the form when the user clicks the button [provided] that he or she is going to, or when they submit another form.

I definitely feel that javascript can help you keep your code consistent, but still like MVC.

0
source

All Articles