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' => ... );
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 ?”