Cake PHP save as file
Monday, February 18th, 2008 - 2:53 am - CakePHP framework
Little snippet code for saving a view to the file.
function admin_file() {
$name = 'exported_file';
$ext = 'txt';
$path = 'tmp'.DS.'files'.DS.$name.'.'.$ext;
$log = new File(APP.$path, true);
$log->write($this->requestAction('admin/users/excel', array('return')));
$log->close();
/***************************/
$this->view = 'Media';
$this->autoLayout = false;
$this->set('download', true);
$this->set('name', Inflector::underscore(Inflector::camelize($name)));
$this->set('extension', $ext);
$this->set('path', $path);
}
function admin_excel() {
$users = $this->Users->findAll();
$this->set(compact('users'));
}