• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MVC options to consider for a simple date function.

Hi all!

I'm trying to wrap my head around MVC with what I want to achieve.
It's nothing complicated, but I'm considering the "best" way to achieve it.

I've written a very tiny function that checks a date and returns a new formatted string, based upon some conditions.

Now, I will want to apply this to almost all dates shown in all Views.
Assuming I place the function in a library (which may be built up later), so I employ DRY tactics, do I:

a. Load the library from the View, call the function and return directly back to the view.
b. Load the library in the controller, alter the date string in $data['Topics'] for EACH row, and just send that to the view like normal.
c. Load the library in the Model, and do the same as above.

Here's a lil background:

Select * from Topics
return result_array() of all topics.

Send the $data['topics'] to the view.

Simply loop through each 'topics' and echo out the results.

It's nothing special, very basic.

I'm considering option B. But how would I have this function perform for each row in $data['Topics']?

Secret Option A...
Would I be best formating the date as I INPUT or UPDATE the table row in the first place, so I don't have to format whilst RETRIEVING?
This sounds good, but I don't like the idea of not using unix timestamps in MySQL

Secret Option B (my favourite)...
Should I just extend the Date library (since I'm loading it anyway), and create my own function there?
This sounds like the most reasonable, easiest, MVC, and DRY'ist.

I ended up extending the Date Helper and simply using my own function, called from the View.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.