Home > csver

csver

Csver is a project mainly written in PHP, it's free.

CakePHP Plugin for making CSVs. Simple, but works.

CSVer

Small CakePHP plugin to handle generating CSVs when given a Model name.

Does what it needs to do right now - options will be added according to need.

  • Uses php-csv http://github.com/ockam/php-csv as a submodule. If you use git, don't forget to git submodule init / git submodule update. If you download the source, you will also have to download php-csv and put it in the plugin vendors folder.

Usage

  • Install in your APP/plugins
  • Copy the csver.php.sample to your APP/config folder. Rename it to csver.php. Open it. Follow the directions to tell CSVer which Models are allowed to generate CSVs.
  • To output a CSV of a model, visit plugin url:
    • example:
      http://localhost/projectname/admin/csver/index/ModelName
    • example generating link:
      $html->link('Export CSV', array('controller'=>'csver', 'action'=>'index', 'ModelName', 'plugin'=>'csver'))
  • The default find automatically excludes id field. You can override it on a per model basis.
    Add a csv method to any model in your app, and the plug will use that to fetch the data. Example:
    /**
     * Results for generating CSV
     * If you want something other than the default, 
     * you can create this method in your model
     * and just return the header & results
     *
     * @return array array('header', 'results');
     **/
    function csv() {
        $results = array();
        $results['header']  = array('license', 'ip');
        $results['results'] = $this->find('all', array('fields'=>$results['header']));
        return $results;
    }
    
  • Used with Cake 1.2 & 1.3.