Php – Reporting Solution in PHP / CodeIgniter – Server side logic vs client side

codeigniterPHPreport generationreporting

I'm building a report for an end user.
They would like to see a list of all widgets… but then also like to see widgets with missing attributes, like missing names, or missing size.

So i was thinking of creating one method that returns json data containing all widgets… and then using javascript to let them filter the data for missing data, instead of requerying the database.

Ultimately, they need to be able to save all "reports" (filtered versions of data) inside a csv file.

These are the two options I'm mulling over:

Design 1

Create 3 separate methods in my controller/model like:

get_all_data()
get_records_with_missing_names()
get_records_with_missing_size()

And then when these methods are called, I would display the data on screen and give them a button to save to csv file.

Design 2

Create one method called get_all_data() and then somehow, give them tools in the view to filter the json data using tables etc… and then letting them save subsets of the data.
The reality is, in order to display all data, I still need to massage the data, and therefore, I know which records are missing attributes. So i'd rather not create separate methods by each filter.

I'm not sure how I would do that just yet but at this point, i would like to know some pros/cons of each method.

Thanks.

Best Answer

Assuming your using Angular.JS, jQuery or similar, I would recommend loading all the data from the server at once, then writing controllers that are able to filter between the different types of lists.

This solution allows for the least amount of load on your server and makes the client do most of the work. This along with the idea of having an application whose lag depends on the local machines filtering (local processing = fast) is much better that having an application that can lag due to network instabilities (network = slow).

That being said, if it is a massive amount of data (> 1 million records), migrating the logic from the client to the server may become reasonable. At this point the local processing may/can take longer that it would be to request the data from the server.

Related Topic