vinai
vinai

Reputation: 91

saving the xml file generated through cakephp 2.3 serialize function

I am using cakephp 2.3 and using the default code from the cookbook. The xml is generated automatically, without having to create any view files.

class PostsController extends AppController {
public function index() {
$this->set(’posts’, $this->paginate());
$this->set(’_serialize’, array(’posts’));
}
}

However, I do not want to display the XML. Instead I want to save the generated XML file in the document root upon click of a button as Posts.xml. How can I do this? Please help.

Upvotes: 0

Views: 827

Answers (1)

mark
mark

Reputation: 21743

You might not have look thoroughly enough: http://book.cakephp.org/2.0/en/controllers/request-response.html#sending-files

It clearly states how to send files with the appropriate headers via response object.

So in your controller action, add:

$this->response->download('filename_for_download.xml');

Upvotes: 2

Related Questions