Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

compare two csv files in modeladmin interface


2 Posts   422 Views


6 October 2012 at 10:50am Community Member, 82 Posts


I know SS has the ability to import csv files and show results. In my case I want to compare two csv files and show the records that match. I assume this would need two upload fields and converting the csv data to arrays which need to be compared. If this is the best way, can someone give an example how to do that on silverstripe?

thanks in advance.


9 October 2012 at 7:56pm (Last edited: 9 October 2012 7:57pm), Forum Moderator, 5511 Posts

SilverStripe also has a Diff library bundled (framework/core/Diff.php) which is used for showing diffs between page versions (DataDifferencer), haven't used it too much so I personally can't help much but take a look to see if those classes can help.

The usage of that is something like

function getDifferences() {
$obj1 = DataObject::get_one('Member');
$obj2 = DataObject::get_one('Member');

return new DataDifferencer($obj1, $obj2);

// then in the template
<% with Differences %>
<% loop ChangedFields %>
<% end_loop %>
<% end_with %>

How you get that displayed to the user depends on your use case. You could embed the template as a FormField within model admin or a separate controller would work.