A
A
Alexey2010-12-10 16:40:32
Yii
Alexey, 2010-12-10 16:40:32

Saving XML from a Yii template?

Good afternoon. It was required to give the user an XML file.
I work in yii. For convenience, I made myself several basic templates and fill them with information.
I decided to generate it using $this->render('export_xml', array('data'=>$data));
In this regard, questions arise. render loads the main layout by default, I want to avoid this.
I solved this issue by making myself an empty layout and $this->layout = '//layouts/blank'; But it seems to me that there is a more logical and correct solution, but I can’t find it yet.
And the second, most important question. Is it possible to force the template to be given as a file?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
calg0n, 2010-12-10
@calg0n

To prevent the layout from loading, use renderPartial():

$this->renderPartial('export_xml', array('data'=>$data));

Is it possible to force the template to be given as a file?

What do you have in mind?

G
Gibbzy, 2010-12-10
@gibbzy

And what about the template?
Unless
$this->layout = false; - In the controller.
And then put any headers, for example, those from the xml file and output whatever you want.

G
gsd, 2013-11-14
@gsd


header('Content-Description: File Transfer');
header('Content-type: text/xml');
header('Content-Disposition: attachment; filename=filename.xml');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question