Codeigniter – Create, export, and download a CSV File from a Model.

If you need to export as a CSV file a model that you already have in your database, you can do the following in your code:

  • Add a method exportCSV in your Controller: application/controller/MyController.php
  • In the preferred view, add the following export link: