7.2. Importing and Exporting

Importing and exporting data are crucial to any application's success. They give the customer more power and flexibility than you can provide with just a web application alone. Why? Because many business applications are intimately tied to spreadsheets, and being able to accept data (and output data) in CSV (comma-separated values) or TSV (tab-separated values) format can make life better for the user along various dimensions. For example, if Claudia had to upload 100 products into her product inventory one at a time, that would be very time-consuming. On the other hand, if she could export a CSV file from Excel and then import that file, she might be able to get all 100 products into the system with one pass, thus saving her a great deal of time and effort.

In this section, you first build an export function for Categories and then take what you've learned and do the same thing for Products. Once all that is done, you will do the slightly harder work of importing data from a spreadsheet into the Products table.

7.2.1. Creating an Export Function for Categories

In this example, you're going to start with the model. Why? Because in CodeIgniter 1.6 and higher, you have access to a very neat tool called dbutil. Its formal name is the Database Utility Class.

What does it do? It's a class that helps you manage your database. The methods found in the class help you list databases, optimize and repair tables, back up your database, and export in both CSV ...

Get Professional CodeIgniter® now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.