Welcome Guest, Not a member yet? Register   Sign In
Use db in libraries is a good way ?
#4

What are you going to do, create a new method in your Excel class every time you want to output different data to a spreadsheet? In the end, you can setup your library however you'd like, but I wouldn't recommend mixing database code with a library that interfaces with PHPExcel, especially if memory use is your major concern.

Personally, I setup a wrapper library for PHPExcel to handle some basic initialization and allow access in a CI-friendly manner. When I need to create a spreadsheet, I get the data from my model and output it through my library. If I needed this functionality more often, I would simply be more inclined to make the library easier to use, but still wouldn't integrate the DB access into the library.

If you're having memory issues when you don't integrate the DB access, you may need to look into the root cause of the memory issues, as I don't see anything in your example code that would indicate a significant savings over retrieving the data from a model. You may also want to consider caching your spreadsheet(s), if possible, if the act of creating the spreadsheet is causing problems.

In the end, a spreadsheet is a View, and the library is simply there to facilitate creating that view.
Reply


Messages In This Thread
Use db in libraries is a good way ? - by casa - 04-06-2015, 10:39 AM
RE: Use db in libraries is a good way ? - by mwhitney - 04-08-2015, 10:40 AM



Theme © iAndrew 2016 - Forum software by © MyBB