How to export sample csv in cakephp

How to export sample csv in cakephp :

1) If you want to export any file in cakephp then put the following lines in your view file where you want to add this functionality.

echo $this->Html->link(Export Sample Csv, array(‘controller’ =>’Test’, ‘action’ => ‘export_csv’,’admin’=>false));

2) After put the above line in view create the one function in the controller and add the following lines in the function.

$this->viewClass = ‘Media’;
$params = array(
‘id’        => ‘test-csv.csv’,
‘name’      => ‘test-csv.csv’,  //set the file name
‘download’  => true,
‘extension’ => ‘csv’,   //set the file extension
‘path’      => ‘webroot’.DS.’files/’   //set the file path where file is located in your folder.
);
$this->set($params);

3) after set this things put the sample csv file in this path in your folder structure “webroot/files”.