Reputation: 596
I'm creating a calendar application in PHP with CodeIgniter. In the main calendar page, My model currently creates an array with each index being one day on the current month. That day is an array containing any events the user may have on that day. Now, should I construct the calendar array in the controller FIRST, then pass it to the model so the model can access the database and fill in all the events, or should I just create the calendar array and fill in the events ALL in the model?
$month = array( 'blank', 'blank', 'day1' => array( event 1, event2), 'day2' => ... );
Upvotes: 1
Views: 894
Reputation: 522626
I'd probably design it so it can work "both ways". The output of the model should be a standardized array, probably along the lines of:
array('2009-08-05' => array('event' => ..., ...), '2009-08-06' => array(...));
I.e. just the pure data.
By default it could spit out the current month, or everything between now and +1 month. It should also take an argument though to change that default behaviour. Either take an array of dates or a range.
I don't know why the first two entries in your example are 'blank'. If your array already represents a month as shown on a calendar sheet, than that would go against MVC. Such presentation issues are to be considered in the View.
Upvotes: 0
Reputation: 401182
That's a difficult question, and I am not sure everyone would do the same way... But here's what I think should be taken into consideration :
getData
", it should only return the array containing the "real" data, and not the one containing the "empty" days ; on the other hand, if it's called "getEventsByDay
", it makes sense to have it return something for each day, even empty ones$model->save($model->load())
should work, I meanIn the end, there is no "good answer" : "it depends" ^^
I don't really know what I'd do in your case ; I suppose it kinda depends on the rest of the application... The question I'd ask myself is "does the notion of an empty day make sense for my Model, or is it just a matter of presentation ?"
Upvotes: 1